I have some trouble to handle swipe on iPhone
, I create in my interface a UISwipeGestureRecognizer
var:
UISwipeGestureRecognizer *swipeRecognizer;
and in my controller : viewDidLoad
method
- (void)viewDidLoad
{
[super viewDidLoad];
// Horizontal swipe
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeMethod:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeRecognizer];
}
And my method to handle swipe is :
-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
NSLog(@"Swipe!");
}
When I run my code and do a swipe I got nothing? I'm supposed to get : Swipe!
Thanks.
I'm surprised that doesn't crash with an unrecognized selector error. Try adding the recognizer to your view instead of to your view controller:
[self.view addGestureRecognizer:swipeRecognizer]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With