[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
EverLearn 1.9.0 に音声認識機能を追加しました
EverLearn 1.9.0 にて音声認識機能を追加しました。ホーム画面から、マイクボタンを押して
-
-
[iOS] INNER JOIN に失敗する
非常に面妖な状況でにわかには信じがたいのだが、iPhone 6 Plus だと問題なく動作する
-
-
薄い iPod touch 4G用ケース SwitchEasy NUDE for iPod touch 4G UltraClear (SW-NUT4-UC) 購入
Retinaディスプレイと、ジャイロの確認のために購入したiPod touch 4G は開発用なので
-
-
Xcode 設定しておくと便利なカスタマイズいろいろ
以前から Xcode はもう一歩使いにくいと思っていたが、iPhone アプリで稼げるのか でカスタ
-
-
LogLocation 1.3.1 で和暦問題に対応しました
4年ぶりに位置情報ログ取りアプリ LogLocations をアップデートしたところ、レビューにて不
-
-
auからUQモバイルに乗り換えてみた
今更ながら、auからUQモバイルに乗り換えてみた。 以前はキャリアを乗り換え
-
-
Corona SDK 調査2日目
昨日はとりあえずCorona SDKを使って付属のLuaのサンプルアプリをiPhone実機上で動かし
-
-
Mac Fan 2020年 6月号
長女のiPhone 6 の画面がバキバキに割れているので、iPhone SE を購入した。
-
-
au で iPhone5 を下取りに出してきた
今ならiPhone 5を32000で買い取りしてもらえるということで、au Shop に行っ
-
-
[iPhone 6 Plus] カラビナ付きケースを買ってみた
iPhone5 はカラビナ付きケースに入れて腰に下げていたのだが、まだiPhone 6 Pl