简体   繁体   English

向UIImageview添加手势

[英]Adding tapgesture to UIImageview

Im trying to add a tapgesture to UIImageview. 我试图给UIImageview添加一个手势。 but the code bellow which im using right now is not working. 但是我现在使用的下面的代码无法正常工作。

I have added this to my viewdidload (notice that LabelNewsImage is my UIImageview): 我已经将其添加到我的viewdidload中(注意LabelNewsImage是我的UIImageview):

LabelNewsImage.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGestureEnlarge = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapGesture:)];
tapGestureEnlarge.numberOfTapsRequired = 1;
[self.LabelNewsImage addGestureRecognizer:tapGestureEnlarge];

You need to properly connect LabelNewsImage to the image view instance. 您需要将LabelNewsImage正确连接到图像视图实例。 Presumably LabelNewsImage is an IBOutlet and your image view is created in an XIB or Storyboard. 大概LabelNewsImageIBOutlet并且您的图像视图是在XIB或Storyboard中创建的。 You need to drag a connection from the LabelNewsImage property to the image view to connect them. 您需要将连接从LabelNewsImage属性拖到图像视图以进行连接。

See the docs (including the video ). 请参阅文档 (包括视频 )。

The response selector tapGesture: Is it probable that you write the method like 响应选择器tapGesture:您编写的方法是否可能像

- (void)tapGesture
{
    // TODO:
}

But it should like this 但它应该像这样

- (void)tapGesture:(NSDictonary *)dic
{
    // TODO:
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM