[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版をアップデート
iPhoneアプリサポートページ の方に書きましたが、4月30日にようやくiPad用のアップデート版
-
-
Apple Special Event 2015
https://www.gizmodo.jp/2015/09/applelive_event_ip
-
-
iPhone/iPad 用ステンシルを買ってみた
makoto_kw氏と、MobileStencil.com の iPhone/iPa
-
-
[i0S8] presentModalViewController で表示している画面で文字が切れる
iOS8 を甘く見ていたようで、いろいろな問題が発生している。 今回発見したのは おんぷち
-
-
Apple iPad まとめ
(2010/01/28 朝5時あたりのapple.comのトップページ) 2010/01/27(水
-
-
アップルストア渋谷で発売日翌日にiPhone 5を買ってきた
2012年9月21日8時に発売されたiPhone5、自分はヨドバシカメラで予約したのだけれどもちょっ
-
-
iOS Developer Program 更新のため Developer Certificates を更新
この前iOS Developer Programを更新したが、1年経ったので Developer C
-
-
[iPhone 開発本] 実践iPad/iPhoneゲームプログラミング 沼田 哲史
MacOS XとiPhone用のゲーム用フレームワーク Karakuri Framework を開発
-
-
[iPhone6plus] 買うかかなり悩み中
9/19 に発売されてからiPhone6Plusを買おうか、買うならいつ買おうか、キャリアは
-
-
[iOS] iPhone とつながるG-SHOCKの注意すべき仕様
CASIO 腕時計 G-SHOCK ジー・ショック Bluetooth Low Energy対応