在UIPanGestureRecognizer中更改ImageView中的图像?

时间:2013-11-06 07:06:27

标签: ios objective-c uiimageview uigesturerecognizer

我有一个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中更改图像。

谢谢

1 个答案:

答案 0 :(得分:0)

试试这个。它解决了你的问题

[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");
}