gpt4 book ai didi

objective-c - UIScrollView subview 中的 UITapGestureRecognizer

转载 作者:太空狗 更新时间:2023-10-30 03:19:53 26 4
gpt4 key购买 nike

我正在尝试在 imageView(也是 scrollView 子项)中使用单击识别器。在 Interface Builder 中,我仅创建并引用了 scrollView。可以滚动,但无法识别单击事件(未记录任何内容)。这是代码:

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

我已经环顾四周并尝试了很多东西。也许看别人一眼会更有帮助。谢谢。

最佳答案

我已经为 imageView 启用了 userInteraction,也为 scrollView 启用了 canCancelContentTouches 选项:

[imageScrollView setCanCancelContentTouches:YES];
[imageView setUserInteractionEnabled:YES];

现在可以了。

关于objective-c - UIScrollView subview 中的 UITapGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5363870/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com