Activity 向下滚动时指示器视图消失
Activity indicator view disappears when scroll down
我在带有自定义节点的按钮上叠加 LoadingIndicatorNode
当我向下和向上滚动 UIActivityIndicatorView
从 LoadingIndicatorNode
消失时,这个按钮被放置在 ASCellNode
中.
这里是LoadingIndicatorNode
class
的代码
@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;
刚刚从 LoadingIndicatorNode
弱引用了 UIActivityIndicatorView
并实现了 didEnterVisibleState
方法并调用了 startAnimating
- (void)didEnterVisibleState {
[super didEnterVisibleState];
[self.activity startAnimating];
}
我在带有自定义节点的按钮上叠加 LoadingIndicatorNode
当我向下和向上滚动 UIActivityIndicatorView
从 LoadingIndicatorNode
消失时,这个按钮被放置在 ASCellNode
中.
这里是LoadingIndicatorNode
class
@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;
刚刚从 LoadingIndicatorNode
弱引用了 UIActivityIndicatorView
并实现了 didEnterVisibleState
方法并调用了 startAnimating
- (void)didEnterVisibleState {
[super didEnterVisibleState];
[self.activity startAnimating];
}