[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
Apple Event Sep 2022 Far Out
毎年恒例の Apple Event が 2022/09/07 に行われた。日本時間は 9/8 2:
-
-
LogLocations 1.3.3 Release
恒例の、年末年始時間があるときの LogLocations のアップデート。久し
-
-
iPad, iPhone, Mac, PC で使える Line6 Mobile Keys
今年のCESで発表されて以来ずっと待っていたLine6のMobile Keysがついに発売される。こ
-
-
Corona SDK 調査4日目
今日はスクリプト言語による効率的ゲーム開発を読んで、ちょっとテストプログラムを書いたくらいであまり進
-
-
“I think the stainless steel looks beautiful when it wears” from The Perfect Thing
傷が付きやすいと言われている iPhone 7 ジェットブラック。ケースを付けるか迷ったら、下記
-
-
iPhone アプリアイコン
iphoneアプリで稼げるのか さんと同様、自分もアイコンを作るのはつらい。 今度アプリを公開すると
-
-
Beginning iPhone 3 Developmentの続編が出るらしい
iPhone開発の入門書としていま一番良いと個人的に思っている、Apressの Beginning
-
-
おんぷちゃん for iPad 大譜表モード+MIDI対応を追加しました
おんぷちゃん for iPad: ぽこ・あ・ぽこ の方がおんぷちゃん for iPad を紹介してく
-
-
[iPhone SDK] Objective-C 2.0 のプロパティ
Objective-Cのプロパティで時々はまるので、メモ。(詳解 Objective-C 2.0 P
-
-
[iOS9] AVSpeechSynthesizer の再生スピードがおかしい
iPhone 6 Plus を iOS9 にアップデートして自作アプリをXcode7 から転送したと