Merge pull request #1042 from binl/bl_control_state_fix

Make ASControlState imitate UIControlState
This commit is contained in:
appleguy
2016-01-06 17:50:27 -08:00
3 changed files with 17 additions and 9 deletions

View File

@@ -47,14 +47,27 @@
[self addSubnode:_titleNode];
[self addSubnode:_imageNode];
[self addTarget:self action:@selector(controlEventUpdated:) forControlEvents:ASControlNodeEventAllEvents];
}
return self;
}
- (void)controlEventUpdated:(ASControlNode *)node
- (void)setEnabled:(BOOL)enabled
{
[super setEnabled:enabled];
[self updateImage];
[self updateTitle];
}
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
[self updateImage];
[self updateTitle];
}
- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
[self updateImage];
[self updateTitle];
}

View File

@@ -60,7 +60,7 @@ typedef NS_OPTIONS(NSUInteger, ASControlState) {
@abstract Indicates whether or not the receiver is highlighted.
@discussion This is set automatically when the there is a touch inside the control and removed on exit or touch up. This is different from touchInside in that it includes an area around the control, rather than just for touches inside the control.
*/
@property (nonatomic, readonly, assign, getter=isHighlighted) BOOL highlighted;
@property (nonatomic, assign, getter=isHighlighted) BOOL highlighted;
/**
@abstract Indicates whether or not the receiver is highlighted.

View File

@@ -46,7 +46,6 @@
}
// Read-write overrides.
@property (nonatomic, readwrite, assign, getter=isHighlighted) BOOL highlighted;
@property (nonatomic, readwrite, assign, getter=isTracking) BOOL tracking;
@property (nonatomic, readwrite, assign, getter=isTouchInside) BOOL touchInside;
@@ -186,10 +185,6 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
// Send the appropriate touch-up control event.
CGRect expandedBounds = CGRectInset(self.view.bounds, kASControlNodeExpandedInset, kASControlNodeExpandedInset);
BOOL touchUpIsInsideExpandedBounds = CGRectContainsPoint(expandedBounds, touchLocation);
if (touchUpIsInsideExpandedBounds) {
self.selected = !self.selected;
}
[self sendActionsForControlEvents:(touchUpIsInsideExpandedBounds ? ASControlNodeEventTouchUpInside : ASControlNodeEventTouchUpOutside)
withEvent:event];