ios - UIImageView 中的 UISwipeGestureRecognizer

标签 ios objective-c uiimageview uigesturerecognizer

我想在 UIImageView 中放置两个滑动手势识别器,但无法识别手势。仅识别点击手势。

这是我的代码:

 - (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];

 }

滑动功能:

 -(IBAction)leftSwipe:(id)sender{ NSLog(@"Left Swipe");    }

谢谢你的提前。

最佳答案

我的解决方案是:

Set a delegate for your gestures and return YES from gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

关于ios - UIImageView 中的 UISwipeGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28154092/

相关文章:

ios - 设备磁航向代码在 iOS 8 上不起作用

ios - 智能应用横幅不调用应用程序 :openURL:sourceApplication:annotation:

ios - 使用自动布局约束 swift 2.1 从中心到顶部为 UIView 设置动画

iPhone int 解析

ios - 如何正确隐藏这些广告横幅?

objective-c - KVO 或如何在 Swift 中监听来自外部的属性更改

ios - iPad 上的 iCarousel 性能问题

swift - 如何将相机按钮添加到 UIImageView

ios - 如何保存照片和文字

image-processing - 读取 RGBA 图像 OpenCV