我在一个带有自定义节点LoadingIndicatorNode
的按钮上进行叠加,当我向下滚动ASCellNode
时,UIActivityIndicatorView
LoadingIndicatorNode
的{{1}}消失了。< / p>
以下是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;
答案 0 :(得分:1)
刚刚从UIActivityIndicatorView
对LoadingIndicatorNode
进行了弱引用并实施了didEnterVisibleState
方法并调用了startAnimating
- (void)didEnterVisibleState {
[super didEnterVisibleState];
[self.activity startAnimating];
}