我想在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");    }

谢谢您的提前。

最佳答案

对我来说,解决方案是:

为您的手势设置一个委托并从中返回YES
手势识别器:应使用手势识别器同时识别:

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

10-10 22:43