gpt4 book ai didi

iphone - 如何遍历 UIView 的所有 subview 及其 subview 及其 subview

转载 作者:IT老高 更新时间:2023-10-28 11:24:15 32 4
gpt4 key购买 nike

如何遍历 UIView 的所有 subview ,以及它们的 subview 和它们的 subview ?

最佳答案

使用递归:

// UIView+HierarchyLogging.h
@interface UIView (ViewHierarchyLogging)
- (void)logViewHierarchy;
@end

// UIView+HierarchyLogging.m
@implementation UIView (ViewHierarchyLogging)
- (void)logViewHierarchy
{
NSLog(@"%@", self);
for (UIView *subview in self.subviews)
{
[subview logViewHierarchy];
}
}
@end

// In your implementation
[myView logViewHierarchy];

关于iphone - 如何遍历 UIView 的所有 subview 及其 subview 及其 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2746478/

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