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

関連記事

Xcodeの Console出力をクリアするキーバインド

いつも忘れるので、メモとして残しておく。Command(⌘)+ Kその他はこちら。 Menu Com

記事を読む

no image

iPhone Developer Program Activation 完了

iPhone Developer ProgramのActivationの件。 木曜日の夜にメールを出

記事を読む

no image

iPad/iPhone 開発本が山のように出るようだ

なんつーかもうすごい状況。もっと出るみたい。 Beginning iP

記事を読む

no image

Pebble E-Paper Watch 届いた! 感想。

追記: Pebble 向けにアプリを作りました。 Kickstarter で iPhone/A

記事を読む

heroku Cedar-10からCedar-14に引越し

2015/11/04 に Cedar-10 stack が終了となる連絡が heroku からきたの

記事を読む

no image

iPadアプリ おんぷちゃん が雑誌に紹介されました

いろいろあって、iPhone/iPad アプリのおんぷちゃん がムジカノーヴァ2011年2月号で紹介

記事を読む

no image

[iPhone SDK] UILabel からポップアップメニューを表示してみる

今作っているアプリに UILabel を複数置いた画面があるが、その UILabelたちは編集

記事を読む

Pebble Time 届いた。これはいいものだ

Pebble Time 発表されたのでさっそく出資 | tokentoken.com で 2015

記事を読む

Olympus Camera Kit (SDK)を製品版に移行

発売が延期されていた OLYMPUS AIR A01も2015/3/25(水)についに発売された。

記事を読む

no image

List切替が便利なTweetList を買ってみた。

フォローする人が増えてくると、なかなかメインのTLを追うのは難しくなる。 このため、複数のListを

記事を読む

Message

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

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

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

Vision Pro カバーケースを買ってみた

[itemlink post_id="11629"]

→もっと見る

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