まーぽんって誰がつけたの?

iOS→Scala→インフラなおじさん技術メモ

viewWillTransitionToSize: withTransitionCoordinator:を使うときはsuperを呼ぶ

画面の回転のイベントで、willRotateToInterfaceOrientation:duration:がありますが、iOS8からはdeprecatedになっています。で、代わりに、viewWillTransitionToSize:withTransitionCoordinator:を使えと書いてあるんですが、ヘッダファイルのコメントにsuperを最後に呼ぶべきだと書いてありました。

/* 
This method is called when the view controller's view's size is changed by its parent (i.e. for the root view controller when its window rotates or is resized). 

If you override this method, you should either call super to propagate the change to children or manually forward the change to children.
*/
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);

要はこんなふうにしろということです。

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
{
    // 回転時のなんらかの処理

    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

superを呼ぶ必要があることをコンパイラで強制とかWarning出せないのかな。。なんかそういうマクロあった気がするんだけど忘れてしまった。