我在带有自定义节点LoadingIndicatorNode
的按钮上进行覆盖,当我向下滚动并从ASCellNode
上移动UIActivityIndicatorView
时,此按钮被放置在LoadingIndicatorNode
中。
这是LoadingIndicatorNode
类的代码
@implementation LoadingIndicatorNode
- (instancetype)init
{
self = [super init];
if (self) {
[self setOpaque:NO];
self.backgroundColor = [UIColor colorWithWhite:1 alpha:0.6];
self.activityNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView * _Nonnull{
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: IPAD ? UIActivityIndicatorViewStyleWhiteLarge : UIActivityIndicatorViewStyleWhite];
activity.color = [UIColor blackColor];
activity.backgroundColor = [UIColor clearColor];
[activity startAnimating];
return activity;
}];
[self addSubnode:self.activityNode];
}
return self;
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
ASCenterLayoutSpec *centerSpec = [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY sizingOptions:ASCenterLayoutSpecSizingOptionDefault child:self.activityNode];
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(10, 0, 10, 0) child:centerSpec];
}
@end
这是一些显示我如何使用它的代码
_loadingIndicator = [[LoadingIndicatorNode alloc] init];
_loadingIndicator.hidden = YES;
[self addSubnode:_loadingIndicator];
[[[[self.viewModel.memberStatusCommand executing] not]
distinctUntilChanged]
subscribeNext:^(NSNumber *x) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:!x.boolValue];
_loadingIndicator.hidden = x.boolValue;
[self updateViewModelData];
[self setNeedsLayout];
}];
layoutSpecThatFits:
方法的覆盖ASOverlayLayoutSpec *overlay = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:_statusButton overlay:_loadingIndicator];
overlay.style.flexBasis = ASDimensionMake(@"50%");
overlay.style.alignSelf = ASStackLayoutAlignSelfStretch;
overlay.style.flexShrink = 1;
overlay.style.flexGrow = 1;
最佳答案
刚刚从UIActivityIndicatorView
弱引用了LoadingIndicatorNode
并实现了didEnterVisibleState
方法,称为startAnimating
- (void)didEnterVisibleState {
[super didEnterVisibleState];
[self.activity startAnimating];
}