我希望能够在点击时检索有关放置在该点击点的所有不同 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/