gpt4 book ai didi

iphone - 在矩形内查找 subview

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

我有一个很大的 UIView 和很多小的 subviews。我需要找到一个区域内的所有 subviews。我目前正在遍历 subviews 并使用 CGRectContainsPoint。这可行,但 90% 的 subview 通常不在我感兴趣的矩形内。

是否有更有效的方法来查找矩形内的所有 subview

谢谢

最佳答案

CGRectContainsRect 会更合适。您仍然需要根据您可以假设的位置遍历所有可能在您的 rect 中的 subview ,但是 CGRectContainsRect 仍然比 CGRectContainsPoint 更有意义。

CGRect area = CGRectMake(10,10,200,200);
NSMutableArray *viewsWithinArea = [[NSMutableArray alloc] init];
for (UIView *aView in [self.view subviews]) {
if(CGRectContainsRect(area,aView.frame)) [views addObject:aView];
}

关于iphone - 在矩形内查找 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7671114/

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