iOS 遍历所有子视图subviews的2种方法
在做项目的过程中,难免有时候会需要利用父子视图的关系去调用一些behavior。
方法一,比较直接
// 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];
浙公网安备 33010602011771号