TouchesBegan 仅在特定的 UIView 中开始

发布于 2024-09-27 08:07:14 字数 562 浏览 0 评论 0原文

我有三个 UIView 实例:

UIView *view1;
UIView *view2;
UIView *view3;

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

 UITouch *touch =[touches anyObject];
 CGPoint startPoint =[touch locationInView:self.view];

}

但我希望 toch-action 只出现在 view2 中。如果我制作: locationInView:view2 则不起作用,

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

 UITouch *touch =[touches anyObject];
 CGPoint startPoint =[touch locationInView:view2];

}

我做错了什么?我如何检查哪个视图是我在 iPhone 上实际可以看到的视图?

I have three UIView instances:

UIView *view1;
UIView *view2;
UIView *view3;

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

 UITouch *touch =[touches anyObject];
 CGPoint startPoint =[touch locationInView:self.view];

}

But i want that the toch-action only go in view2. It doesnt work if i make: locationInView:view2

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

 UITouch *touch =[touches anyObject];
 CGPoint startPoint =[touch locationInView:view2];

}

What do I wrong? How can i check, which view is the view i actually can see on my iphone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一刻暧昧 2024-10-04 08:07:14

在您不希望处理触摸的视图中将 userInteractionEnabled 设置为 false。

set userInteractionEnabled to false in the view in which you don't want your touch to be handled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文