自分で作ってるアプリのViewの構造がよくわからなくなってしまった。標準UIの中身がどういう構造になっているのか調べてみたい。そんなときは、dumpAllViewsを使ってみよう。画面に表示されているUIViewを渡すと、すべてのUIViewが芋づる式に表示されます。
-(void)dumpAllViews:(UIView *) view{
UIView * rootView = [self getRootView:view];
[self showSubViews:rootView depth:0];
}
-(UIView *)getRootView: (UIView *) view{
while([view superview]){
view = [view superview];
}
return view;
}
-(void)showSubViews:(UIView *) view depth:(int)depth{
NSLog(@"%@%@ (%lf,%lf) (%lf,%lf)",
[@"----------" substringToIndex:depth],
[view class],
view.frame.origin.x,
view.frame.origin.y,
view.frame.size.width,
view.frame.size.height);
for(UIView * subview in [view subviews]){
[self showSubViews:subview depth:depth + 1];
}
}
UIView * rootView = [self getRootView:view];
[self showSubViews:rootView depth:0];
}
-(UIView *)getRootView: (UIView *) view{
while([view superview]){
view = [view superview];
}
return view;
}
-(void)showSubViews:(UIView *) view depth:(int)depth{
NSLog(@"%@%@ (%lf,%lf) (%lf,%lf)",
[@"----------" substringToIndex:depth],
[view class],
view.frame.origin.x,
view.frame.origin.y,
view.frame.size.width,
view.frame.size.height);
for(UIView * subview in [view subviews]){
[self showSubViews:subview depth:depth + 1];
}
}
実行例
Tabbed Applicationで実行してみるとこんな感じ。ドキュメントに記載されていないクラスがちらほら出ていますね。
UIViewDumper[14013:c07] UIWindow (0,0) (320,480)
UIViewDumper[14013:c07] -UILayoutContainerView (0,0) (320,480)
UIViewDumper[14013:c07] --UITransitionView (0,0) (320,431)
UIViewDumper[14013:c07] ---UIViewControllerWrapperView (0,20) (320,411)
UIViewDumper[14013:c07] ----UIView (0,0) (320,411)
UIViewDumper[14013:c07] -----UILabel (20,79) (280,43)
UIViewDumper[14013:c07] -----UITextView (20,162) (280,88)
UIViewDumper[14013:c07] ------UITextSelectionView (0,0) (0,0)
UIViewDumper[14013:c07] ------UIImageView (273,0) (7,88)
UIViewDumper[14013:c07] ------UIWebDocumentView (0,0) (280,88)
UIViewDumper[14013:c07] ------UITextSelectionView (0,0) (0,0)
UIViewDumper[14013:c07] --UITabBar (0,431) (320,49)
UIViewDumper[14013:c07] ---_UITabBarBackgroundView (0,0) (320,49)
UIViewDumper[14013:c07] ---UIImageView (0,-3) (320,3)
UIViewDumper[14013:c07] ---UITabBarButton (2,1) (156,48)
UIViewDumper[14013:c07] ----UITabBarSelectionIndicatorView (0,2) (156,44)
UIViewDumper[14013:c07] ----UITabBarSwappableImageView (54,2) (48,32)
UIViewDumper[14013:c07] ----UITabBarButtonLabel (67,34) (22,13)
UIViewDumper[14013:c07] ---UITabBarButton (162,1) (156,48)
UIViewDumper[14013:c07] ----UITabBarSwappableImageView (54,2) (48,32)
UIViewDumper[14013:c07] ----UITabBarButtonLabel (60,34) (37,13)
UIViewDumper[14013:c07] -UILayoutContainerView (0,0) (320,480)
UIViewDumper[14013:c07] --UITransitionView (0,0) (320,431)
UIViewDumper[14013:c07] ---UIViewControllerWrapperView (0,20) (320,411)
UIViewDumper[14013:c07] ----UIView (0,0) (320,411)
UIViewDumper[14013:c07] -----UILabel (20,79) (280,43)
UIViewDumper[14013:c07] -----UITextView (20,162) (280,88)
UIViewDumper[14013:c07] ------UITextSelectionView (0,0) (0,0)
UIViewDumper[14013:c07] ------UIImageView (273,0) (7,88)
UIViewDumper[14013:c07] ------UIWebDocumentView (0,0) (280,88)
UIViewDumper[14013:c07] ------UITextSelectionView (0,0) (0,0)
UIViewDumper[14013:c07] --UITabBar (0,431) (320,49)
UIViewDumper[14013:c07] ---_UITabBarBackgroundView (0,0) (320,49)
UIViewDumper[14013:c07] ---UIImageView (0,-3) (320,3)
UIViewDumper[14013:c07] ---UITabBarButton (2,1) (156,48)
UIViewDumper[14013:c07] ----UITabBarSelectionIndicatorView (0,2) (156,44)
UIViewDumper[14013:c07] ----UITabBarSwappableImageView (54,2) (48,32)
UIViewDumper[14013:c07] ----UITabBarButtonLabel (67,34) (22,13)
UIViewDumper[14013:c07] ---UITabBarButton (162,1) (156,48)
UIViewDumper[14013:c07] ----UITabBarSwappableImageView (54,2) (48,32)
UIViewDumper[14013:c07] ----UITabBarButtonLabel (60,34) (37,13)