iPhone How-to:如何递归dump UIView
来源:互联网 发布:由 诲女知之乎 编辑:程序博客网 时间:2024/06/16 18:56
在学习和调试iPhone 界面或者某个控件的过程中,递归地dump出UIView是一个了解界面结构很有效的方法。这样不仅可以更好地发现问题,还可以定制某些系统的标准控件。要解决这类问题,很自然会想到递归函数。实现如下:
void dumpViews(UIView* view, NSString *label, NSString *indent) {
Class klass = [view class];
NSString *classDescription = getFullClassDescription(klass);
if ([label compare:@""] == NSOrderedSame)
NSLog(@"%@ %@", classDescription, NSStringFromCGRect(view.frame));
else
NSLog(@"%@ %@ %@", label, classDescription, NSStringFromCGRect(view.frame));
for (NSUInteger i = 0; i < [view.subviews count]; i++)
{
UIView *subView = [view.subviews objectAtIndex:i];
NSString *newIndent = [[NSString alloc] initWithFormat:@" %@", indent];
NSString *newLabel = [[NSString alloc] initWithFormat:@"%@%d:", newIndent, i];
dumpViews(subView, newLabel, newIndent);
[newLabel release];
[newIndent release];
}
}
其中getFullClassDescription是用来获取某个类的继承关系描述:
NSString* getFullClassDescription(Class klass) {
NSString *description = [klass description];
while ([klass superclass])
{
klass = [klass superclass];
description = [description stringByAppendingFormat:@":%@", [klass description]];
}
return description;
}
利用dumpViews对某应用的主窗体进行“偷窥”后输出结果如下:
UIWindow:UIView:UIResponder:NSObject {{0, 0}, {320, 480}}
0: UILayoutContainerView:UIView:UIResponder:NSObject {{0, 0}, {320, 480}}
0: UINavigationTransitionView:UIView:UIResponder:NSObject {{0, 0}, {320, 480}}
1: UINavigationBar:UIView:UIResponder:NSObject {{0, 0}, {320, 44}}
0: UINavigationItemView:UIView:UIResponder:NSObject {{160, 8}, {0, 27}}
- iPhone How-to:如何递归dump UIView
- iPhone How-to:如何调整UIView的Z-Order
- iPhone How-to:给UIView拍照
- How to analyze dump
- how to dump oracle block
- How to analyze Thread Dump
- [HOW TO]如何在iPhone应用程序中发送邮件
- iPhone How-to:如何更改UISwitch的提示文本
- iPhone How-to:如何更改UISwitch的提示文本
- iPhone How-to:如何更改UISwitch的提示文本
- 如何为UIView添加用户事件响应事件 && How to add a touch event to a UIView?
- How to Export/import database dump correctly
- How to use Oracle Dump Function
- How to Create Dump File for Applications
- How to dump Oracle Data Block?
- How to read crash dump of Android
- how to analysis the crash dump
- how to dump undo header and block
- 分享几个iOS游戏开发的有利工具
- 当点击一个按钮时把gridview中的值导入到excel中
- 第5章类和对象(一)
- 网络接口库函数MPR.dll
- 第5章类和对象(一)续
- iPhone How-to:如何递归dump UIView
- Remote System Explorer之FTP移植(vsftpd)
- <jsp:usebean> 标签中的scope取值范围区别
- Server2003安装SQL2000企业版
- 线段树相关问题
- 点击任意exe文件打开自己程序---SDK实现
- Cocoa中监听、观察和通知的五种方法
- WIFEXITED/WEXITSTATUS/WIFSIGNALED
- 申请内存的函数