[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
iOS9からGKSession over Bluetoothが無効に
ユーザの方からおんぷ先生アプリが接続できないという報告があり調べていたところ、iOS9からGameK
-
-
新アプリ「コードちゃん」を公開しました
速報:新 iPad 発表。Apple Pencil対応で3万7800円から - Engadget
-
-
MacPeople 2012 5月号にはほしいガジェットがたくさん紹介されてる
定期購読しているMacPeopleの今月号(5月号)で面白い製品がたくさん紹介されていたのでメモを書
-
-
暗記サポートアプリ YUBImarker
暗記サポートアプリを探している。 YUBImaker はちょっと良さそうなんだけれども、なかなかiP
-
-
HTML5+CSS3で作る 魅せるiPhoneサイト
iPhone向けWebページの実例を使って、CSS+HTML5の使い方を説明してくれる本。 CS
-
-
[iOS SDK] モーダル表示したViewController を取得する
UIViewControllerの presentViewController:animated:c
-
-
おんぷちゃん for iPad 1.3.3 Submit
今回は紅白歌合戦を見ながらSubmit。 相変わらずうちの娘が譜読みに苦労していて新しい曲を弾く
-
-
児童手当 認定請求書申請 2024 「請求者が養育をする18歳に達する日以降の最初の3月31日までの子の数」とは?
2024年に受給していない人には手紙が届くらしい。 電子申請も可能ということで、iPhone
-
-
これは便利 iPhoneプログラミングUIKit詳解リファレンス
Amazonでの評判も良いし、書店で立ち読みしていくつか有用な情報を見つけたので、iPhoneプログ