gpt4 book ai didi

ios - 在繁忙的 uiview 上处理单击

转载 作者:行者123 更新时间:2023-11-29 13:01:07 24 4
gpt4 key购买 nike

所以我有一个 UIVIew,它承载一个 ImageView ,用户可以在其中放大,另一个 ScrollView 响应双击,当然还有滚动,还有一些按钮。我需要显示一个顶部菜单(有点像照片应用程序),当用户在 View 中的任何地方单击一次时,我会显示/隐藏该菜单),我在实现这个时遇到了麻烦,因为点击可能发生在 imageview 或一个 ScrollView 。

所以我实现了

  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

只有当用户点击他触摸 View 的某个地方时,它才会工作并且完成工作,而不是任何 subview !

感谢任何帮助。

最佳答案

假设您的所有 View 都是 self.view 的 subview ,使用 UITapGestureRecongizer 更有意义,然后将其添加到整个 View 。

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


- (void)tapped
{
NSLog(@"Tapped");
}

无论您点击哪个 View ,使用该代码都会注销“Tapped”。然后,您可以更改 tapped 方法来执行您需要它执行的任何操作。

关于ios - 在繁忙的 uiview 上处理单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19755618/

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