who knows which would be the following gesture: Imagine I click within some region (say a button), I hold the finger down, don't release it, and move the finger outside the region area?? is there some gesture to it?
I have a button which starts up in a selected/highlighted state, but if a user clicks on it (using a finger), doesn't release his/her finger, moves his/her finger outside the button area, my button gets deselected - which is something I don't want. Can someone help?
You need to handle "Touch Up Outside" button event.
==EDIT==
You can override UIControl
's *TrackingWithTouch:withEvent:
methods to get the behaviour you want:
@interface CustomButton : UIButton
@end
implementation
@interface CustomButton()
// Auxiliary property
@property(nonatomic, assign) BOOL isHighlightedBeforeTouch;
@end
@implementation CustomButton
-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
self.isHighlightedBeforeTouch = self.highlighted;
return [super beginTrackingWithTouch:touch withEvent:event];
}
-(BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
BOOL result = [super continueTrackingWithTouch:touch withEvent:event];
if( self.isHighlightedBeforeTouch && !CGRectContainsPoint(self.bounds, [touch locationInView:self]) ) {
dispatch_async(dispatch_get_main_queue(), ^{
self.highlighted = self.isHighlightedBeforeTouch;
});
}
return result;
}
-(void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
dispatch_async(dispatch_get_main_queue(), ^{
self.highlighted = self.isHighlightedBeforeTouch;
});
[super endTrackingWithTouch:touch withEvent:event];
}
@end
to change highlighted property eg on when button is pressed:
-(IBAction)buttonPressed:(UIButton*)sender
{
dispatch_async(dispatch_get_main_queue(), ^{
[sender setHighlighted:![sender isHighlighted]];
});
}
您需要使用UIGesuture识别器:UIPanGestureRecognizer。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.