[英]UISwipeGestureRecognizer in UIImageView
I want to put two swipe gesture recognizers in a UIImageView but gestures aren't recognized. 我想在UIImageView中放置两个滑动手势识别器,但无法识别手势。 Only recognizes the tap gesture. 仅识别轻击手势。
This is my code: 这是我的代码:
- (void)viewDidLoad {
//Acciones
img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[urls
objectAtIndex:index]]]];
UIImage *img2;
if (img.size.height > img.size.width) {
img2 = [[UIImage alloc] initWithCGImage: img.CGImage scale:1.0 orientation: UIImageOrientationUp];
}else{
img2 = [[UIImage alloc] initWithCGImage: img.CGImage scale:1.0 orientation: UIImageOrientationRight];
}
imageSelected.image = img2;
[imageSelected setUserInteractionEnabled:YES];
imageSelected.contentMode = UIViewContentModeScaleAspectFit;
imageSelected.backgroundColor= [UIColor whiteColor];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(exitAction:)];
[singleTap setNumberOfTapsRequired:1];
[imageSelected addGestureRecognizer:singleTap];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[imageSelected addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[imageSelected addGestureRecognizer:swipeRight];
}
Swipe function: 滑动功能:
-(IBAction)leftSwipe:(id)sender{ NSLog(@"Left Swipe"); }
Thank you for advance. 谢谢您的提前。
The solution for me was: 我的解决方案是:
Set a delegate for your gestures and return YES from gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 为您的手势设置一个委托,并从gestureRecognizer中返回YES:shouldRecognizeWithWithGestureRecognizer:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.