簡體   English   中英

UIImageView中的UISwipeGestureRecognizer

[英]UISwipeGestureRecognizer in UIImageView

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

謝謝您的提前。

我的解決方案是:

為您的手勢設置一個委托,並從gestureRecognizer中返回YES:shouldRecognizeWithWithGestureRecognizer:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM