[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アプリで週末起業
2009年7月に出た本なので、今となってはちょっと古いが、当時の熱気は感じられる。 iPhoneアプ
-
-
iPhoneアプリ おんぷちゃん開発日記 ボタン表示の複数言語対応
そろそろiPhone OS 4 beta 3の開発環境に移行しようと思っているのだが、環境を移行して
-
-
「iPhoneの動作が遅くなる場合があります」に対応する
年末年始は休みがあるのでブログ更新頻度が高い。以前から気になっていた、LogLocationsを起動
-
-
MacPeople 2012 5月号にはほしいガジェットがたくさん紹介されてる
定期購読しているMacPeopleの今月号(5月号)で面白い製品がたくさん紹介されていたのでメモを書
-
-
[iOS SDK] 処理中の表示に便利 SVProgressHUD
以前 MBProgressHUD の記事を書いたが、たまに使うと使い方をすっかり忘れている。 やり
-
-
SwitchEasy NUDE for iPhone5 を買ってみた。まだ様子見の方がよさそう
SwitchEasy NUDE for iPhone 5 UltraClearSwitchEasy
-
-
[iOS SDK] CGRect 関連の便利機能
CGRect を使っていていつも忘れて調べてしまうのでメモしてみる。 CGRect の変数を拡大・
-
-
おんぷちゃん 1.9.0 MIDI対応
おんぷちゃん 1.9.0 で MIDI キーボードに対応しました。(まだ App Store にてレ
-
-
[iPhone5] ステータスバーの謎の○(丸)表示
iPhone5使い始めて2日目、自宅でもLTE表示が出ていたのになぜかある時から○表示になってしまっ