[英]Adding Tap Gesture on UIImage
I am trying to make clickable UIImage, where the user can click it then it'll animate... 我正在尝试制作可点击的UIImage,用户可以点击它然后它会动画...
i am working with the UIScrollVIew that's why i used the UITapGesture instead of touchesBegan, and it seems that UIGestureRecognizer is not compatible with UIImage... 我正在使用UIScrollVIew,这就是我使用UITapGesture而不是touchesBegan的原因,而且似乎UIGestureRecognizer与UIImage不兼容......
am i right? 我对吗?
i keep receiving this error message 我一直收到此错误消息
receiver type 'UIImage' for instance message does not declare a method with selector 'addGestureRecognizer' 接收器类型'UIImage'例如消息没有声明带有选择器'addGestureRecognizer'的方法
is there any other way? 还有其他方法吗?
You have to add TapGesture in UIImageView not UIImage 你必须在UIImageView而不是UIImage中添加TapGesture
imgView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
tapGesture1.numberOfTapsRequired = 1;
[tapGesture1 setDelegate:self];
[imgView addGestureRecognizer:tapGesture1];
[tapGesture1 release];
You can response to the tap with the defined selector and do stuff there 您可以使用已定义的选择器响应点击并在那里执行操作
- (void) tapGesture: (id)sender
{
//handle Tap...
}
您必须将手势添加到UIImageView,而不是UIImage
You can simply add a TapGestureRecognizer to a UIImageView. 您只需将TapGestureRecognizer添加到UIImageView即可。 You have to use a UIImageView because gesture recognizer are only allowed to be added to views. 您必须使用UIImageView,因为只允许将手势识别器添加到视图中。
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero]; UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]; tapRecognizer.numberOfTapsRequired = 1; [someView addGestureRecognizer:tapRecognizer];
You can response to the tap with the defined selector and do stuff there 您可以使用已定义的选择器响应点击并在那里执行操作
- (void)tapAction:(UITapGestureRecognizer *)tap { // do stuff }
Try with UIButton
instead of UIIMage
and make the UIButton
type custom . 尝试使用UIButton
而不是UIIMage
并使UIButton
类型自定义 。 And on clicking the same you can show the animation. 点击相同内容即可显示动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.