UIView的层次结构--code

非常方便的查看自己的view的层次结构,继承关系。

对苦苦调试UI的你也许有点启发。

// 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 classdescription]];

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 allocinit];

[self dumpViewself.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


转自:http://blog.csdn.net/hamasn/article/details/8216584



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值