UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedGesture:)];
swipe.direction = UISwipeGestureRecognizerDirectionRight;
swipe.numberOfTouchesRequired = 1;
[self.myLabel.superview addGestureRecognizer:swipe];
- (void)swipedGesture:(UIGestureRecognizer *)recognizer
{
NSLog(@"I swiped ;)");
}
So, this is what happens: I have a label called myLabel. and when I swipe right it should print the NSLog I swiped, but nothing happens. What’s the reason? What have I done wrong here? Could someone help me edit my code to make this work ?
Dont you need to add this swipe gesture to the
UILabel? you are adding it to the superview of that label.change –
[self.myLabel.superview addGestureRecognizer:swipe];to –
[self.myLabel addGestureRecognizer:swipe];UPDATE: Also as justin points, please set
userInteractionEnabledtoYESfor the label like so –[self.myLabel setUserInteractionEnabled:YES];