我需要检查一个iPhone程序的视图层次结构 [英] I need to inspect the view hierarchy on an iPhone program
本文介绍了我需要检查一个iPhone程序的视图层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
按照以下方式,我的iPhone程序中的视图结构如何确定? Yannick建议,Erica Sadun有代码这里打印视图层次结构(使用类和帧信息)。您可以使用以下界面将其设置为UIView类别:
#import< UIKit / UIKit.h>
@interface UIView(ExploreViews)
- (void)exploreViewAtLevel:(int)level;
@end
和实现:
#importUIView + ExploreViews.h
void doLog(int level,id formatstring,...)
{
int i; (i = 0; i< level; i ++)printf();
va_list arglist;
if(formatstring)
{
va_start(arglist,formatstring);
id outstring = [[NSString alloc] initWithFormat:formatstring arguments:arglist];
fprintf(stderr,%s\\\
,[outstring UTF8String]);
va_end(arglist);
}
}
@implementation UIView(ExploreViews)
- (void)exploreViewAtLevel:(int)level;
{
doLog(level,@%@,[[self class] description]);
doLog(level,@%@,NSStringFromCGRect([self frame]));
(UIView * subview in [self subviews])
[subview exploreViewAtLevel:(level + 1)];
}
@end
How do I determine what the view structure on my iPhone program while running on the simulator?
解决方案
Along the lines of what Yannick suggests, Erica Sadun has code here that pretty-prints the view hierarchy (with class and frame information). You can make this into a UIView category with the following interface:
#import <UIKit/UIKit.h>
@interface UIView (ExploreViews)
- (void)exploreViewAtLevel:(int)level;
@end
and implementation:
#import "UIView+ExploreViews.h"
void doLog(int level, id formatstring,...)
{
int i;
for (i = 0; i < level; i++) printf(" ");
va_list arglist;
if (formatstring)
{
va_start(arglist, formatstring);
id outstring = [[NSString alloc] initWithFormat:formatstring arguments:arglist];
fprintf(stderr, "%s\n", [outstring UTF8String]);
va_end(arglist);
}
}
@implementation UIView (ExploreViews)
- (void)exploreViewAtLevel:(int)level;
{
doLog(level, @"%@", [[self class] description]);
doLog(level, @"%@", NSStringFromCGRect([self frame]));
for (UIView *subview in [self subviews])
[subview exploreViewAtLevel:(level + 1)];
}
@end
这篇关于我需要检查一个iPhone程序的视图层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文