gpt4 book ai didi

ios - 是否可以找到iphone上某个点存在的所有 subview ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:08:52 26 4
gpt4 key购买 nike

我希望能够在点击时检索有关放置在该点击点的所有不同 subview 的信息。例如,如果有一个背景,并且在它前面是一个游戏角色,我希望能够点击那个角色,它会检索到该角色和背景都在那个点击点的信息.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//retrieve info about what other subviews lie behind at this point
}

最佳答案

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[touches anyObject];
CGPoint p=[touch locationInView:self.view];
NSLog(@"Coordiantes of Tap Point:(%f,%f)", p.x, p.y);

NSArray *anArrayOfSubviews = [self.view subviews];
NSMutableArray *requiredSubviewArray = [NSMutableArray array];

for (UIView *aSubView in anArrayOfSubviews){
if(CGRectContainsPoint(aSubView.frame, p)) {
//aSubView is there at point 'p'
[requiredSubviewArray addObject:aSubView];
}
}
// requiredSubviewArray contains all the Subviews at the Tap Point.

关于ios - 是否可以找到iphone上某个点存在的所有 subview ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18756418/

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