[iOS SDK] UIDeviceOrientation ではまる
すぐURLが変更されそうだが、2013/02/16 時点だと、Supporting Multiple Interface Orientations という記事がiOS Developer Library にある。
View Controller Programming Guide for iOS: Supporting Multiple Interface Orientations
そこに、下記のようなコードがあり、UIDeviceOrientation を普通に使っている。
@implementation PortraitViewController - (void)awakeFromNib { isShowingLandscapeView = NO; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)orientationChanged:(NSNotification *)notification { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView) { [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self]; isShowingLandscapeView = YES; } else if (UIDeviceOrientationIsPortrait(deviceOrientation) && isShowingLandscapeView) { [self dismissViewControllerAnimated:YES completion:nil]; isShowingLandscapeView = NO; } }
このため、このコードをそのまま流用して画面回転対応コードを書いていたら、UIDeviceOrientation には UIDeviceOrientationFaceUp や UIDeviceOrientationFaceDown があるので、それに該当してしまい不具合を発生させてしまった。
typedef enum { UIDeviceOrientationUnknown, UIDeviceOrientationPortrait, UIDeviceOrientationPortraitUpsideDown, UIDeviceOrientationLandscapeLeft, UIDeviceOrientationLandscapeRight, UIDeviceOrientationFaceUp, UIDeviceOrientationFaceDown } UIDeviceOrientation;
ということで、UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
を使ったり、
– (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
を使ったりしよう。
iOS6 になって
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
がdeprecated になってしまったためにいろいろ混乱させられているが didRotateFromInterfaceOrientation などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
iPhoneゲーム開発本 iPhone Games Projects
iPhone Games Projects、ようやくざっと読んだので内容をまとめてみる。 出版元のA
-
iPhone/iPad 用ステンシルを買ってみた
makoto_kw氏と、MobileStencil.com の iPhone/iPa
-
自作アプリを売り買いできる Apptopia
Apptopia というところからメールが来たので調べてみたところ、どうやらAndroid
-
[iOS SDK] UIAlertView が消えた後にキーボードが表示される
昔書いたコードで、UIAlertView に setAlertViewStyle で UIAlert
-
[iPhone 開発本] iOS SDK Hacks の感想など。
iOS SDK Hacksは発売前から話題になっていて、発売日は10/23だが前日に新宿ジュンク堂に
-
おんぷちゃん for iPad 1.9.0が異常終了する
ユーザの方から下記の連絡がありました。 おんぷちゃんfor iPadを使用させて頂いておりま
-
2歳の娘がiPadを離しません タッチ! うごく うたえほん
開発用に買ったのでアプリ開発時以外はあまり使っていなかったiPadはここしばらく完全に2歳の娘用にな
-
iPhone 3G/3GS用ホルダーケース レイアウト RT-P2LC3 カラビナつき
カバンを持っていないときに、iPhoneをジーパンのポケットに入れておくのはちょっと不安。 なの
-
LogLocations 1.4.0 写真表示対応
行動ログは取りたいが、何も操作したくない。という自分のようなずぼらなログ好きユーザ向けのアプリ、L
-
はじめてのiPhoneプログラミング 正誤表
発売されてからすぐ はじめてのiPhoneプログラミング を購入し、必要に応じて少しずつ読み進めてい