gpt4 book ai didi

ios - UILabel 问题的 UITapGesture 选择器

转载 作者:行者123 更新时间:2023-11-28 21:11:34 25 4
gpt4 key购买 nike

我为 self.view 和 UILabel(mainView 的 subview )添加了 tapGesture,每个执行不同的选择器。

但是调用了唯一的主视图 tapGesture 而没有调用标签 taggesture。如何处理?

代码如下:

UITapGestureRecognizer  *tapGesForSelf = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesForSelf:)];
[self.view addGestureRecognizer:tapGesForSelf];


UITapGestureRecognizer *tapLblClick = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesForLbl:)];
[lbl addGestureRecognizer:tapLblClick];

对于两个选择器,只有一种方法称为 tapGesForSelf。这里lbl是self.view的子view。

最佳答案

试试这个

- (void)viewDidLoad {
[super viewDidLoad];
[_lbl setUserInteractionEnabled:YES];
UITapGestureRecognizer *tapGesForSelf = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesForSelf:)];
[self.view addGestureRecognizer:tapGesForSelf];
UITapGestureRecognizer *tapLblClick = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesForLbl:)];
[_lbl addGestureRecognizer:tapLblClick];
[tapGesForSelf requireGestureRecognizerToFail:tapLblClick];
}
- (void)tapGesForSelf:(UITapGestureRecognizer *)gesture
{
NSLog(@"self");
}
- (void)tapGesForLbl:(UITapGestureRecognizer *)gesture
{
NSLog(@"label");
}

关于ios - UILabel 问题的 UITapGesture 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42900443/

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