2017-03-29 6 views
3

Ich mache eine Überlagerung auf einer Schaltfläche mit einem benutzerdefinierten Knoten LoadingIndicatorNode Diese Schaltfläche befindet sich in einem ASCellNode, wenn ich scroll nach unten und oben UIActivityIndicatorView von LoadingIndicatorNode verschwindet. HierAktivitätsanzeige verschwindet, wenn nach unten scrollen

ist der Code von LoadingIndicatorNode Klasse

@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 

Hier einige Code zeigt, wie ich es verwenden

_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]; 
    }]; 

Overlay von layoutSpecThatFits: Methode

ASOverlayLayoutSpec *overlay = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:_statusButton overlay:_loadingIndicator]; 
    overlay.style.flexBasis = ASDimensionMake(@"50%"); 
    overlay.style.alignSelf = ASStackLayoutAlignSelfStretch; 
    overlay.style.flexShrink = 1; 
    overlay.style.flexGrow = 1; 

Antwort

1

gerade einen schwachen Verweis zu UIActivityIndicatorView von LoadingIndicatorNode und implementiert didEnterVisibleState Methode und genannt startAnimating

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