diff --git a/AsyncDisplayKit/ASControlNode+Subclasses.h b/AsyncDisplayKit/ASControlNode+Subclasses.h index 107de031e0..9257911150 100644 --- a/AsyncDisplayKit/ASControlNode+Subclasses.h +++ b/AsyncDisplayKit/ASControlNode+Subclasses.h @@ -19,6 +19,12 @@ NS_ASSUME_NONNULL_BEGIN @interface ASControlNode (Subclassing) +/** + @abstract Indicates whether or not at least one target was added to the receiver + @discussion YES if the receiver has at least one target; NO otherwise. + */ +@property (nonatomic, readonly, assign, getter=isTargetAdded) BOOL targetAdded; + /** @abstract Sends action messages for the given control events. @param controlEvents A bitmask whose set flags specify the control events for which action messages are sent. See "Control Events" in ASControlNode.h for bitmask constants. diff --git a/AsyncDisplayKit/ASControlNode.m b/AsyncDisplayKit/ASControlNode.m index f68fd3a02e..cf1c98ab47 100644 --- a/AsyncDisplayKit/ASControlNode.m +++ b/AsyncDisplayKit/ASControlNode.m @@ -7,6 +7,7 @@ */ #import "ASControlNode.h" +#import "ASDisplayNode+Subclasses.h" #import "ASControlNode+Subclasses.h" // UIControl allows dragging some distance outside of the control itself during @@ -22,6 +23,7 @@ { @private // Control Attributes + BOOL _targetAdded; BOOL _enabled; BOOL _highlighted; @@ -46,6 +48,7 @@ } // Read-write overrides. +@property (nonatomic, readwrite, assign, getter=isTargetAdded) BOOL targetAdded; @property (nonatomic, readwrite, assign, getter=isTracking) BOOL tracking; @property (nonatomic, readwrite, assign, getter=isTouchInside) BOOL touchInside; @@ -77,12 +80,19 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v _enabled = YES; - // As we have no targets yet, we start off with user interaction off. When a target is added, it'll get turned back on. - self.userInteractionEnabled = NO; return self; } #pragma mark - ASDisplayNode Overrides +- (void)didLoad +{ + [super didLoad]; + + // As we have no targets yet, we start off with user interaction off. When a target is added, it'll get turned back on. + if (!self.targetAdded) { + self.userInteractionEnabled = NO; + } +} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // If we're not interested in touches, we have nothing to do.