[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
EDAMTimestamp と NSDate の相互変換
Evernote SDKを使ったアプリで EDAMTimestamp を DBに格納する前に NSD
-
-
LogLocation 1.3.1 で和暦問題に対応しました
4年ぶりに位置情報ログ取りアプリ LogLocations をアップデートしたところ、レビューにて不
-
-
iTunes Connect の支払先をCitibankに変更
iTunes Connectからの送金を三井住友銀行の口座で受け取っていたが、毎月4000円の手数料
-
-
iPhone開発のネタ帳: コールアウト代用部品を作る
Map Kit を使うと、地図上に吹き出しのようなものを表示できる。この吹き出しのようなものをコ
-
-
アップルiPodイベント 2009.9.9
9月9日のアップルのiPodイベント rock and roll が迫ってきた。 しばらく前から楽し
-
-
LogLocations 1.4.5 リリース
LogLocations 1.4.5 をリリースしました。 LogLocat
-
-
Corona SDK を試してみた
どうやら結構いまさらなようだが、Corona SDK を試してみた。 Corona SDK は同じソ
-
-
iOS16でaurioTouch の inBufferFramesが1になる
https://developer.apple.com/library/archive/sampl
-
-
Apple買収後の TestFlight を利用してみた
TestFlight は昔から利用していたが、2014年に Apple に買収 されてしまった。その
-
-
iOS13からpresentViewControllerの挙動が変わっている
; を実行してViewControllerを表示していま