iOS8を使用。と で、ビューのフレーム サイズUIViewController's
が正しくありませviewDidLoad
んviewDidAppear
。から正しいフレームサイズを取得してviewDidLayoutSubviews
ビューの更新を実行できましたが(レイアウトを無効にする必要があります)、回転を処理するよりもviewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
無意味になり、2つの方法がそれを解決します。
レイアウトを無効にして無意味な計算やレイアウトなどを実行する必要があるかどうかわからないため、理想的willTransitionToSize
には と ではなく と呼ばれます。didLayoutSubviews
回転やフレーム サイズの変更に関連するあらゆる種類のマジック フラグの使用を避けたいと考えています。
これが発生する前に、View Controllerビューの「真の」サイズを取得する方法はありますか?
編集
コード例を次に示します。
-(void)viewDidLoad {
[super viewDidLoad];
NSLog(@"My Frame = %@",NSStringFromCGRect(self.view.frame)); // prints 320x568 i.e. the whole screen
// more setup code...
self.someView = [SomeClass alloc] initWithFrame:self.view.bounds];
self.someView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// add some more views and masks
}
-(void)viewDidAppear {
[super viewDidAppear];
NSLog(@"My Frame = %@",NSStringFromCGRect(self.view.frame)); // prints 320x568 i.e. the whole screen
// view "sticks" out the bottom of the screen still - don't know if I need to layout "self.someView". I could add "viewWillLayoutSubviews" but than rotation wouldn't be animated - because I wouldn't know which condition to take...
}
// if the view controller rotates than need to update appearance in a nice animated way
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self updateAppearance];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
}];
}