[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アプリやiPadアプリのモックをさくさく作れる iPadアプリ iMockups
iPhoneやiPadアプリのモックアップをサクサク作れそうなiPadアプリ iMockups をR
-
-
iPhone SDKでユーザデータをローカルに保存したい
一応5日より次のiPhoneアプリの開発を始めた。 前回のアプリはアプリの設定をちょこっとローカルに
-
-
iPhone アプリアイコン
iphoneアプリで稼げるのか さんと同様、自分もアイコンを作るのはつらい。 今度アプリを公開すると
-
-
Begininng iPhone 3 Development 入手
はじめてのiPhoneプログラミングの原書 Beginning iPhone Development
-
-
[IOS] iOS オープンソースライブラリ徹底活用 菊田剛著 秀和システム
ふらっと家の近くの書店に寄ったところたまたま発見した本。 最近発売されたようだ。 21章で69
-
-
MacPeople は2014年10月号からスマホアプリ開発者向け雑誌に?
。 最近 MacPeople の記事がずいぶんアプリ開発者寄りだなと思っていたところ、2014
-
-
Bluetooth MIDIキーボード KORG microKEY Airを買ってみた
以前から気になっていた、Bluetooth MIDI キーボード KORG microKey Ai
-
-
iPhone/iPad で教育
この本は面白そう。今後は教育分野での応用も増えていくだろう。 その時に、iPhone/iPad は教
-
-
省メモリプログラミング
昔買った「省メモリプログラミング」を読み返してみたら、Objective-Cで採用している参照カウン