如何从UIImageView获取UIImage同时使用UITapGestureRecognizer点击UIImageView

时间:2012-09-27 10:41:05

标签: objective-c uiimageview uitapgesturerecognizer

我已将UITapGestureRecognizer添加到UIImageViewUITableViewCellUITapGestureRecognizer处理程序位于UITableViewCell的FileOwner中。

当我点击UIImageView时,正在调用处理程序方法,其参数也有UIImageView但是当我检查imageview.image时,我发现imageview没有有任何形象:它去了哪里?

2 个答案:

答案 0 :(得分:1)

谢谢惠普...我也是这样做但是它对我不起作用......现在我通过使用UIButton代替UIImageView来做到这一点。我用按钮附加了处理程序,设置了button.backgroundImage,然后将图像放在任何地方,我想......无论如何,谢谢。 :)

答案 1 :(得分:0)

这是我在我的项目中所使用的&它运作良好。

    UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    [self.view addGestureRecognizer:singleFingerTap];

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
    CGPoint location = [recognizer locationInView:[recognizer.view superview]];


    //Do stuff here...
    // I assume that your imgview is imgView11

    if (imgView11.frame.origin.x < location.x && location.x < something
        && imgView11.frame.origin.y < location.y && location.y < something) {

        largeImgView.image = imgView11.image;
    }
}

如果您可以分享您的代码,那么我将编辑我的答案以解决您的问题