[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
[iOS] iOS6 から起動時に一度 Portraitになる挙動が変更された模様
iOS6 からは画面の回転関係の仕様が整理されたのか、いろいろと変更が入っている。 まず - (B
-
-
MacFan 2017年5月号でアプリ紹介されました
Mac Fan 2017年5月号 でおんぷちゃん for iPad を紹介していただきました。ありが
-
-
[iPhone アプリマーケティング] Yappler.com に登録してみた
たまたま検索していて発見した、Yappler.com に試しに登録してみた。 iPhoneアプリ開発
-
-
タッチ!にほんちずHD Ver.1.1.0 Submit
タッチ!にほんちずHDのバージョンアップ版(Ver.1.1.0)を App Store に提出しまし
-
-
WWDC にひとりで参加する人向け情報
WWDC 2011 に行ってきたの続編。 自費で1人で参加したのだけれども、当時あまりそういう人向
-
-
さらに薄いiPhoneケース SwitchEasy Nude Ultra Clear
以前 eggshell for iPhone クリアを購入したが、Homeボタンを押す際などに力が入
-
-
Apple iPad まとめ
(2010/01/28 朝5時あたりのapple.comのトップページ) 2010/01/27(水
-
-
リズムくん Ver.1.2 アップデート 2012/02/05
iPhone用リズム学習アプリ リズムくん Ver.1.2 アップデートを App Stor
-
-
Apple Special Event 2013
2013年には下記が発表された。 iPhone 5siPhone 5cついにドコモでも発売
-
-
Xcode + Assembla で Subversion でソース管理
ソースコードはUSB HDDにバックアップしているが、震災が来たらHDDを持って逃げられるとは思え