UIScrollView 子视图中的 UITapGestureRecognizer
我正在尝试在 imageView (也是滚动视图子项)中使用单击识别器。 在界面生成器中,我仅创建并引用了滚动视图。 可以进行滚动,但无法识别单击事件(不记录任何内容)。 这是代码:
- (void)loadView {
[super loadView];
UIImage *myImage = [UIImage imageNamed:@"img1.jpg"];
imageView = [[UIImageView alloc] initWithImage:myImage];
[myImage release];
// add gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[imageView addGestureRecognizer:singleTap];
[singleTap release];
[imageScrollView setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
[imageScrollView addSubview:imageView]; }
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
// single tap handling
NSLog(@"sinlgeTap called"); }
我已经环顾了几个小时并尝试了很多东西。也许别人的目光能提供更多帮助。 谢谢。
I'm trying to use a single tap recognizer in an imageView (that is also a scrollView child).
In Interface Builder I've created and referentiated the scrollView only.
Works the scrolling but the single tap event is not recognized (nothing is logged).
Here's the code:
- (void)loadView {
[super loadView];
UIImage *myImage = [UIImage imageNamed:@"img1.jpg"];
imageView = [[UIImageView alloc] initWithImage:myImage];
[myImage release];
// add gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[imageView addGestureRecognizer:singleTap];
[singleTap release];
[imageScrollView setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
[imageScrollView addSubview:imageView]; }
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
// single tap handling
NSLog(@"sinlgeTap called"); }
I've looked around for hours and tried many things. Maybe a look of someone else can help much more.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经为 imageView 启用了 userInteraction ,也为scrollView启用了 canCancelContentTouches 选项:
它现在可以工作了。
I've enabled the userInteraction for imageView and also the canCancelContentTouches option for the scrollView:
It works now.