UIView的层次结构–code

转:http://blog.dongliwei.cn/archives/uiview-tree-code

// Recursively travel down the view tree, increasing the indentation level for children

- (void)dumpView:(UIView *)aView atIndent:(int)indent into:(NSMutableString *)outstring

{

for (int i = 0; i < indent; i++) [outstring appendString:@"--"];

[outstring appendFormat:@"[%2d] %@\n", indent, [[aView class] description]];

for (UIView *view in [aView subviews])

[self dumpView:view atIndent:indent + 1 into:outstring];

}

// Start the tree recursion at level 0 with the root view

- (NSString *) displayViews: (UIView *) aView

{

NSMutableString *outstring = [[NSMutableString alloc] init];

[self dumpView: self.window atIndent:0 into:outstring];

return [outstring autorelease];

}

// Show the tree

- (void)logViewTreeForMainWindow

{

//  CFShow([self displayViews: self.window]);

ATLogInfo(@"The view tree:\n%@", [self displayViews:self.window]);

}

具体用法就是在你想知道你的view的层次的时候,调用一下这个logViewTreeForMainWindow函数就可以了。

比方说:下面这个就是我的打印结果。非常清晰明了!

[ 0] UIWindow

–[ 1] UILayoutContainerView

—-[ 2] UINavigationTransitionView

——[ 3] UIViewControllerWrapperView

——–[ 4] UIView                 —–rootViewController

———-[ 5] UITableView

————[ 6] ServerViewCell_iphone

————–[ 7] UITableViewCellContentView

————[ 6] ServerViewCell_iphone

————–[ 7] UITableViewCellContentView

—-[ 2] UINavigationBar

——[ 3] UINavigationBarBackground

——[ 3] UILabel

——[ 3] UIButton

——–[ 4] UIImageView

——–[ 4] UIImageView

–[ 1] UIView                  —-backView

–[ 1] UITransitionView

—-[ 2] UIView                —-CameraPlayerView.

——[ 3] UIView              for zoom.–frameView.

——–[ 4] UIImageView

——[ 3] UIImageView

——[ 3] UILabel

——–[ 4] UIImageView

——[ 3] UIImageView

——[ 3] UINavigationBar

——–[ 4] UINavigationBarBackground

——–[ 4] UINavigationItemView

—-[ 2] UILayoutContainerView

——[ 3] UINavigationTransitionView   —–recordVideoView

——–[ 4] UIViewControllerWrapperView

———-[ 5] UIView

————[ 6] UITableView

————–[ 7] UIImageView

————–[ 7] UIImageView

————[ 6] UIToolbar

————–[ 7] _UIToolbarBackground

————–[ 7] UISegmentedControl

——[ 3] UINavigationBar

——–[ 4] UINavigationBarBackground

——–[ 4] UILabel

——–[ 4] UIButton

———-[ 5] UIImageView

———-[ 5] UIButtonLabel

时间: 2024-08-29 10:53:48

UIView的层次结构–code的相关文章

iOS开发——UI篇OC篇&amp;UIView/UIWindow/UIScreen/CALayer

UIView/UIWindow/UIScreen/CALayer 1.UIScreen可以获取设备屏幕的大小. 1 2 3 4 5 6 7 // 整个屏幕的大小 {{0, 0}, {320, 480}} CGRect bounds = [UIScreen mainScreen].bounds; NSLog(@"UIScreen bounds: %@", NSStringFromCGRect(bounds)); // 应用程序窗口大小 {{0, 20}, {320, 460}} CGRe

iOS项目开发中的知识点与问题收集整理

注:本文并非绝对原创 大部分内容摘自 http://blog.csdn.net/hengshujiyi/article/details/20943045 文中有些方法可能已过时并不适用于现在的开发环境. 1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用). 其实在代码里还是可以设置的,那就是删除背景view  [[self.searchBar.subviews objectAtIndex:0] remov

iOS项目开发知识点

前言部分 注:本文并非绝对原创 大部分内容摘自 http://blog.csdn.net/hengshujiyi/article/details/20943045 文中有些方法可能已过时并不适用于现在的开发环境. 1.Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用). 其实在代码里还是可以设置的,那就是删除背景view  [[self.searchBar.subviews objectAtIndex:0]

【解决方法】iOS 开发小技巧

1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用). 其实在代码里还是可以设置的,那就是删除背景view [[self.searchBar.subviews objectAtIndex:0] removeFromSuperview]; 2,NSDate: [java] view plaincopy 字母  日期或时间元素    表示     示例 G     Era   标志符     Text     

walker代理深入浅出——程序的启动原理(下)(探究 UIWindow)

上一节主要讲解了程序的启动原理UIApplication 的启动,以及 main 函数的执行,现在主要讲解界面的加载以及执行部分. UIWindow 下面先看看Apple的官方文档 Apple官方文档 UIWindow继承自UIView,UIWindow是一种特殊的UIView,通常在一个程序中只会有一个UIWindow,但可以手动创建多个UIWindow,同时加到程序里面.即使有多个UIWindow对象,也只有一个UIWindow可以接受到用户的触屏事件(即主窗口). iOS程序启动完毕后,先

iOS项目开发中的知识点与问题收集整理(Part 一)

前言部分 注:本文并非绝对原创 大部分内容摘自 http://blog.csdn.net/hengshujiyi/article/details/20943045 文中有些方法可能已过时并不适用于现在的开发环境. 1.Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用). 其实在代码里还是可以设置的,那就是删除背景view  [[self.searchBar.subviews objectAtIndex:0]

(转载)关于iOS的一些简单用法

1. 了解main函数,  UIApplication是初始化程序的核心,它接受4个参数.  其中argc和argv两个参数来自于main()接受的两个参数:另外两个String型参数分别表示程序的主要类(principal class)和代理类(delegate class) 2. plist xml格式文件通常用于储存用户设置pch  预编译文件头xib  Interface Builder 的图形界面设计文档StoryBoard是iOS 5的新特征,旨在代替历史悠久的NIB/XIB 3.

iOS7下滑动返回与ScrollView共存二三事

[转载请注明出处] = =不是整篇复制就算注明出处了亲... iOS7下滑动返回与ScrollView共存二三事 [前情回顾] 去年的时候,写了这篇帖子iOS7滑动返回.文中提到,对于多页面结构的应用,可以替换interactivePopGestureRecognizer的delegate以统一管理应用中所有页面滑动返回的开关,比如在UINavigationController的派生类中 1 //我是一个NavigationController的派生类 2 - (id)initWithRootV

UI-Day01--UIWindow &amp; UIWindowLevel(四)

UIWindow & UIWindowLevel详解 一.UIWindow是一种特殊的UIView,通常在一个程序中只会有一个UIWindow,但可以手动创建多个UIWindow,同时加到程序里面.UIWindow在程序中主要起到三个作用: 1.作为容器,包含app所要显示的所有视图 2.传递触摸消息到程序中view和其他对象 3.与UIViewController协同工作,方便完成设备方向旋转的支持 二.通常我们可以采取两种方法将view添加到UIWindow中: 1.addSubview 直