[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
Miselu C.24 届いた
Bluetooth 鍵盤 Miselu C.24 が2015年3月にようやく届い
-
-
詳解 Objective-C 2.0 改訂版 2010年12月17日発売
まだ書店で遭遇できてないけれども荻原さんの詳解 Objective-C 2.0の改訂版が発売されてい
-
-
[iPhone6plus] 買うかかなり悩み中
9/19 に発売されてからiPhone6Plusを買おうか、買うならいつ買おうか、キャリアは
-
-
[iPhone 開発本] iPhoneのオモチャ箱 でしばらく遊べそう
cocos2d/Box2Dを調べたいと思っていたら丁度発売されたので買ってみた。 実際にcocos2
-
-
iTunes Connect でアプリページを表示できない
いつからかわからないけれども、iTunes Connect で自分のアプリを表示できなくなってしまい
-
-
Jony Ive: The Genius Behind Apple’s Greatest Products
Jony Ive: The Genius Behind Apple's Greatest Produ
-
-
Apple Special Event 2019
https://japanese.engadget.com/2019/09/10/5-iphone
-
-
iPhoneアプリネットワーク+GPSプログラミング 橋本佳幸
去年12月に読んで、途中まで感想を書いてそのままにしていた。ネットワーク関連の実用的なコードが多くて
-
-
iOS15にアップデート
2021/09/21にiOS15が公開され、そろそろ初期不具合もわかってきた頃だと思いアッ
-
-
Apple Event Apple Watch 3/10 2AM JST
Apple Watch に関するイベントが3/10(火)2:00AM JSTに行われるら