首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UISwipeGestureRecognizer in UIImageView

UISwipeGestureRecognizer in UIImageView
EN

Stack Overflow用户
提问于 2015-01-26 16:16:54
回答 1查看 495关注 0票数 1

我想在一个UIImageView中放置两个滑动手势识别器,但是手势是不被识别的。只认得踢踏舞的手势。

这是我的密码:

代码语言:javascript
复制
 - (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];

 }

滑动功能:

代码语言:javascript
复制
 -(IBAction)leftSwipe:(id)sender{ NSLog(@"Left Swipe");    }

谢谢你提前给我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-27 11:01:22

我的解决方案是:

为您的手势设置一个委托,然后从gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:返回YES

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28154092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档