Delay set userInteractionEnabled to NO until didLoad

This commit is contained in:
Michael Schneider
2016-02-01 20:09:26 -08:00
parent 191d978154
commit 89eae1213d
2 changed files with 18 additions and 2 deletions

View File

@@ -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.

View File

@@ -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.