[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
Apple Developer Program更新2019
今年も更新。税別 11800円だった。 2009年から継続しているようだ。もう11回
-
-
fitbit 日本語版を買ってみた
2013年3月に発売された fitbit ソフトバンクBB、Bluetooth 4.0接続の
-
-
安くなったPFUのSnapLiteを買ってみた
昔からほしかったが高くて手が出なかったPFUのSnapLiteが2018年3月に販売終了になったらし
-
-
iPhone開発のネタ帳: コールアウト代用部品を作る
Map Kit を使うと、地図上に吹き出しのようなものを表示できる。この吹き出しのようなものをコ
-
-
[iPhone開発本] iPad電子書籍アプリ開発ガイドブック
2010年8月23日発売らしい。3570円と高いけれども、内容は濃そうだ。 目次はImpress D
-
-
[iPhone SDK] iPhone SDK で Singleton
自分でもよく忘れるので、備忘録的に書いてみる。 iPhone SDKで開発をしていて、時々シングルト
-
-
[iPhone 開発本] Objective-C 逆引きハンドブック
854ページの大著。C&R研究所というところから出版されている。ページはこちら。目次はこちら
-
-
[iPhone開発のネタ帳] loadView, viewDidLoad と viewDidUnload 2011/08/12
拙作のiPadアプリ タッチ!にほんちず や タッチ!ヨーロッパ地図でUIWebViewContro
-
-
Guideline 2.5.10 – Performance – Software Requirements で Reject
2019年3月27日以降、iPhone Xs Maxの画面サイズ6.5インチのスクリーンショットが
-
-
iOS用アイコンをまとめて生成する
しばらく開発してきたアプリがようやくリリースできる状態になってきたので、知り合いのデザイナーと飲み