向下滚动

时间:2017-03-29 11:22:59

标签: ios objective-c asyncdisplaykit

我在一个带有自定义节点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;

1 个答案:

答案 0 :(得分:1)

刚刚从UIActivityIndicatorViewLoadingIndicatorNode进行了弱引用并实施了didEnterVisibleState方法并调用了startAnimating

- (void)didEnterVisibleState {
    [super didEnterVisibleState];
    [self.activity startAnimating];
}