iOS6の回転処理ではまったのでメモ
iOS6でViewControllerの回転処理が従来と変更されました。
いままで、
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
を使ってたのが、
- (NSUInteger)supportedInterfaceOrientations;
- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
の3つを使わなきゃいけないようです。
古い方のメソッドは呼ばれなくなってしまうので、
今までにリリースしたアプリが、回っちゃいけない画面で回ったりして困ります。
さらに、UINavigationControllerやUITabBarControllerを使っている場合は、
これらのサブクラスを作って、そこで上記のメソッドをオーバーライドする必要があるようです。
さらに、ページによってローテーションするしないを変えたい場合はさらに場合分けをしなきゃいけないようです。
いままでのアプリを修正する上で、
さすがにそれは面倒なのでカテゴリを作って対処しました。
@implementation UINavigationController (AutoRotate)
- (NSUInteger)supportedInterfaceOrientations{
return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
- (BOOL)shouldAutorotate{
return [self.viewControllers.lastObject shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
@end