[iOS SDK] UIDeviceOrientation ではまる

公開日: : iPad, iPhone

すぐ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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。

関連記事

no image

[iOS] iOS6 から起動時に一度 Portraitになる挙動が変更された模様

iOS6 からは画面の回転関係の仕様が整理されたのか、いろいろと変更が入っている。 まず - (B

記事を読む

MacFan 2017年5月号でアプリ紹介されました

Mac Fan 2017年5月号 でおんぷちゃん for iPad を紹介していただきました。ありが

記事を読む

no image

[iPhone アプリマーケティング] Yappler.com に登録してみた

たまたま検索していて発見した、Yappler.com に試しに登録してみた。 iPhoneアプリ開発

記事を読む

no image

タッチ!にほんちずHD Ver.1.1.0 Submit

タッチ!にほんちずHDのバージョンアップ版(Ver.1.1.0)を App Store に提出しまし

記事を読む

no image

WWDC にひとりで参加する人向け情報

WWDC 2011 に行ってきたの続編。 自費で1人で参加したのだけれども、当時あまりそういう人向

記事を読む

no image

さらに薄いiPhoneケース SwitchEasy Nude Ultra Clear

以前 eggshell for iPhone クリアを購入したが、Homeボタンを押す際などに力が入

記事を読む

Apple iPad まとめ

(2010/01/28 朝5時あたりのapple.comのトップページ) 2010/01/27(水

記事を読む

no image

リズムくん Ver.1.2 アップデート 2012/02/05

iPhone用リズム学習アプリ リズムくん Ver.1.2 アップデートを App Stor

記事を読む

Apple Special Event 2013

2013年には下記が発表された。 iPhone 5siPhone 5cついにドコモでも発売

記事を読む

no image

Xcode + Assembla で Subversion でソース管理

ソースコードはUSB HDDにバックアップしているが、震災が来たらHDDを持って逃げられるとは思え

記事を読む

Message

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

DELL 32インチディスプレイ U3223QE 購入

Dell U3223QE は解像度 3840x216

WWDC 2023 Vision Pro発表

2023/6/5 (日本時間 2023/06/06 2AM)のWWD

M1 MacBook Air を Venturaにアップデートする

M1 MacBook Air を macOS Montere

iOS16でaurioTouch の inBufferFramesが1になる

https://developer.apple.com/librar

おんぷちゃん for iPad 2.0.0リリース

あけましておめでとうございます。今年もよろしくお願いします。

→もっと見る

  • 2013年2月
     123
    45678910
    11121314151617
    18192021222324
    25262728  
PAGE TOP ↑