【问题标题】:Change Image in ImageView within UIPanGestureRecognizer?在 UIPanGestureRecognizer 中的 ImageView 中更改图像?
【发布时间】:2013-11-06 07:06:26
【问题描述】:

我有一个 ImageView 和数组中的图像 URL。我想在 UIImageView 上下载并显示这些图像,但是发出这个我在该视图上面临两个手势的问题,因此仅在 ImageView 上的内部手势不希望工作。

我的代码如下所示

  [self.imageView setUserInteractionEnabled:YES];


            UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
            UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];

            // Setting the swipe direction.
            [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
            [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];

            // Adding the swipe gesture on image view
            [self.imageView addGestureRecognizer:swipeLeft];
            [self.imageView addGestureRecognizer:swipeRight];





- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {

    if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
        NSLog(@"Left Swipe");

    }
    if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
        NSLog(@"Right Swipe");

    }
}

handleSwipe 方法没有被调用,当我移动它时也会打开侧边菜单,因为手势应用与在其 iOS 应用中打开的 facebook 侧边菜单相同。

当整个父视图也使用 Gesture 时,如何更改 ImageView 中的图像。

谢谢

【问题讨论】:

    标签: ios objective-c uiimageview uigesturerecognizer


    【解决方案1】:

    试试这个。它解决了两个 ypur 问题

    [self.imageView setUserInteractionEnabled:YES];
    
    
            UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe)];
            UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe)];
    
            // Setting the swipe direction.
            [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
            [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
    
            // Adding the swipe gesture on image view
            [self.imageView addGestureRecognizer:swipeLeft];
            [self.imageView addGestureRecognizer:swipeRight];
    
    
    
    
    
    - (void)handleLeftSwipe
    {
        NSLog(@"Left Swipe");
    }
    
    - (void)handleRightSwipe
    {
        NSLog(@"Left Swipe");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多