gpt4 book ai didi

ios - 在触摸事件中,确定触摸了哪个 subview

转载 作者:行者123 更新时间:2023-11-29 02:44:27 26 4
gpt4 key购买 nike

我有一个带有多个 subview 的 View Controller 。当用户点击屏幕时,我想知道哪个 subview 被触摸了。有没有办法确定这一点?

-(void)touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
UIView *touchedView = ...
if(touchedView == self.importantView){
//do something cool.
}
}

最佳答案

试试这个:

UITouch *touch = (UITouch *)[touches anyObject];
UIView *touchView = touch.view;

关于ios - 在触摸事件中,确定触摸了哪个 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25319115/

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