Sop*_*are 42 debugging cocoa-touch ios view-hierarchy
这是一个有用的例程,当您想知道正在创建的内容以及它的位置时,您可以在iOS应用程序中使用该例程来遍历视图层次结构.
此例程将视图层次结构转储到NSLog()
从传入的视图开始.子视图在子视图数组中显示它们的索引,所有超类按顺序用冒号分隔,最后是帧大小.
要转储应用程序的整个视图层次结构,请调用以下方法:
dumpViews([[UIApplication sharedApplication] keyWindow], @"", @"");
Run Code Online (Sandbox Code Playgroud)
要显示摄像机视图的层次结构,请在控制器中覆盖此方法: navigationController:willShowViewController:viewController:animated:
并像这样调用转储例程:
dumpViews(self.modalViewController.view, @"", @"");
Run Code Online (Sandbox Code Playgroud)
对于所有其他观点:
dumpViews(myView, @"", @"");
Run Code Online (Sandbox Code Playgroud)
void dumpViews(UIView* view, NSString *text, NSString *indent)
{
Class cl = [view class];
NSString *classDescription = [cl description];
while ([cl superclass])
{
cl = [cl superclass];
classDescription = [classDescription stringByAppendingFormat:@":%@", [cl description]];
}
if ([text compare:@""] == NSOrderedSame)
NSLog(@"%@ %@", classDescription, NSStringFromCGRect(view.frame));
else
NSLog(@"%@ %@ %@", text, 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 *msg = [[NSString alloc] initWithFormat:@"%@%d:", newIndent, i];
dumpViews(subView, msg, newIndent);
[msg release];
[newIndent release];
}
}
Run Code Online (Sandbox Code Playgroud)
UIView:UIResponder:NSObject {{0, 0}, {320, 480}} 0: PLCameraView:UIView:UIResponder:NSObject {{0, 0}, {320, 480}} 0: UIView:UIResponder:NSObject {{0, 0}, {320, 427}} 1: UIImageView:UIView:UIResponder:NSObject {{10000, 10000}, {320, 480}} 2: UIView:UIResponder:NSObject {{0, 427}, {320, 53}} 3: PLCropOverlay:UIView:UIResponder:NSObject {{0, 0}, {320, 480}} 0: UIImageView:UIView:UIResponder:NSObject {{0, 20}, {320, 96}} 1: PLCropLCDLayer:UIView:UIResponder:NSObject {{0, 20}, {320, 96}} 2: TPBottomDualButtonBar:TPBottomButtonBar:TPBottomBar:UIView:UIResponder:NSObject {{0, 384}, {320, 96}} 0: TPPushButton:UIThreePartButton:UIPushButton:UIControl:UIView:UIResponder:NSObject {{22, 26}, {128, 47}} 1: TPCameraPushButton:TPPushButton:UIThreePartButton:UIPushButton:UIControl:UIView:UIResponder:NSObject {{170, 26}, {128, 47}} 0: UIImageView:UIView:UIResponder:NSObject {{51, 12}, {26, 19}}
归档时间: |
|
查看次数: |
5239 次 |
最近记录: |