gpt4 book ai didi

iphone - UIScrollView 和检测点击手势的 subview

转载 作者:行者123 更新时间:2023-12-03 19:11:59 24 4
gpt4 key购买 nike

我已将 TapGestureRecognizer 添加到我的 self.view 中:

    tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:tap];
[tap release];

该 View 包含一个带有图像和标签的 UIScrollView。我想检测用户是否点击标签。

- (void)singleTap:(UIGestureRecognizer*)gestureRecognizer {

CGPoint pt = [gestureRecognizer locationInView:self.view];

UIView *v = [self.view hitTest:pt withEvent:nil];
if ([v isKindOfClass:[UILabel class]]) {
NSLog(@"label!");
return;
}
// else do other stuff if its not a label

但是我没有看到标签!在我的日志中。

最佳答案

我认为这是因为 userInteractionEnabledUILabel 上默认为 NO。尝试将其打开。

编辑:这确实是一个猜测,但只是为了确认,Apple 文档上的 [UIView hitTest:withEvent:] 状态:

This method ignores view objects that are hidden, that have disabled user interaction, or have an alpha level less than 0.01.

关于iphone - UIScrollView 和检测点击手势的 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7237766/

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