[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

EDAMTimestamp と NSDate の相互変換

Evernote SDKを使ったアプリで EDAMTimestamp を DBに格納する前に NSD

記事を読む

LogLocation 1.3.1 で和暦問題に対応しました

4年ぶりに位置情報ログ取りアプリ LogLocations をアップデートしたところ、レビューにて不

記事を読む

no image

iTunes Connect の支払先をCitibankに変更

iTunes Connectからの送金を三井住友銀行の口座で受け取っていたが、毎月4000円の手数料

記事を読む

no image

iPhone開発のネタ帳: コールアウト代用部品を作る

Map Kit を使うと、地図上に吹き出しのようなものを表示できる。この吹き出しのようなものをコ

記事を読む

no image

アップルiPodイベント 2009.9.9

9月9日のアップルのiPodイベント rock and roll が迫ってきた。 しばらく前から楽し

記事を読む

LogLocations 1.4.5 リリース

LogLocations 1.4.5 をリリースしました。 LogLocat

記事を読む

no image

Corona SDK を試してみた

どうやら結構いまさらなようだが、Corona SDK を試してみた。 Corona SDK は同じソ

記事を読む

iOS16でaurioTouch の inBufferFramesが1になる

https://developer.apple.com/library/archive/sampl

記事を読む

Apple買収後の TestFlight を利用してみた

TestFlight は昔から利用していたが、2014年に Apple に買収 されてしまった。その

記事を読む

iOS13からpresentViewControllerの挙動が変わっている

    ; を実行してViewControllerを表示していま

記事を読む

Message

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ember Mug 2のACアダプタをUSB Type-Cに変えてみた

冬になると活躍する Ember Mug 2 の充電器は付属のACアダ

Wi-Fi6Eルータ TP-Link AXE5400購入

Wi-Fi6E を試してみたくなり、TP-Link AXE5

児童手当 認定請求書申請 2024 「請求者が養育をする18歳に達する日以降の最初の3月31日までの子の数」とは?

2024年に受給していない人には手紙が届くらしい。 電子申請も

Vision Proアプリ開発本 8/24、8/26に発売

Vision Proアプリ開発入門 P400が 8/24 に発売、V

Developer Strap が日本でも購入可能に

USアカウントでしか購入できなかった Vision Pro 用 De

→もっと見る

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