UIView
ビューアピアランスチェーン中のフレームや、ストーリーボードと従来のxibのフレームに関連する違いについて、いつ安全に質問できるかわかりません。
Xcode4.5.1で2つの異なる非常に単純な単一UIViewController
プロジェクトを作成しました。最初はxibを使用した標準のシングルビューテンプレートを使用し、2番目はストーリーボードを使用しました。のソースコードViewController.m
–両方のプロジェクトで同一–を以下に示します。IBでは、をドラッグしUIScrollView
て、コントローラーのコンセントに適切に配線しました。
ソースでわかるように、ビューの外観チェーンのさまざまなポイントでスクロールビューのフレームをログアウトしています。の(0,0)であるため、なぜそれらが異なるのか、および/またはUIScrollViewフレームを安全にクエリできるのはいつかわかりませんviewDidLoad
。
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"viewDidLoad scrollView.frame = (%3.0f,%3.0f)",self.scrollView.frame.size.width,self.scrollView.frame.size.height);
}
- (void)viewWillLayoutSubviews {
NSLog(@"viewWillLayoutSubviews scrollView.frame = (%3.0f,%3.0f)",self.scrollView.frame.size.width,self.scrollView.frame.size.height);
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"viewWillAppear scrollView.frame = (%3.0f,%3.0f)",self.scrollView.frame.size.width,self.scrollView.frame.size.height);
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"viewDidAppear scrollView.frame = (%3.0f,%3.0f)",self.scrollView.frame.size.width,self.scrollView.frame.size.height);
}
@end
xibでの結果
2012-10-23 11:49:48.316 ScrollTest[83262:c07] viewDidLoad scrollView.frame = (320,548)
2012-10-23 11:49:48.318 ScrollTest[83262:c07] viewWillAppear scrollView.frame = (320,548)
2012-10-23 11:49:48.321 ScrollTest[83262:c07] viewWillLayoutSubviews scrollView.frame = (320,548)
2012-10-23 11:49:48.328 ScrollTest[83262:c07] viewDidAppear scrollView.frame = (320,460)
ストーリーボードでの結果
2012-10-23 11:49:58.762 ScrollTestStoryboard[83308:c07] viewDidLoad scrollView.frame = ( 0, 0)
2012-10-23 11:49:58.763 ScrollTestStoryboard[83308:c07] viewWillAppear scrollView.frame = ( 0, 0)
2012-10-23 11:49:58.765 ScrollTestStoryboard[83308:c07] viewWillLayoutSubviews scrollView.frame = ( 0, 0)
2012-10-23 11:49:58.772 ScrollTestStoryboard[83308:c07] viewDidAppear scrollView.frame = (320,460)