[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
Beginning iPhone 3 Developmentの続編が出るらしい
iPhone開発の入門書としていま一番良いと個人的に思っている、Apressの Beginning
-
-
[iPhone SDK] Objective-C 2.0 のプロパティ
Objective-Cのプロパティで時々はまるので、メモ。(詳解 Objective-C 2.0 P
-
-
[iTunes Connect] Price End Date には安売りの終わる次の日を入れるべき
App Store では、ランキングに現れないアプリは存在しないも同然、という話がある。 App
-
-
新アプリ「コードちゃん」を公開しました
速報:新 iPad 発表。Apple Pencil対応で3万7800円から - Engadget
-
-
英単語学習アプリ EverLearn 1.4.0 を公開しました
ようやく、iOS7 に対応した EverLearn 1.4.0 を公開しました。 i
-
-
[iOS SDK] iTunes Connect ではまる
iOS8リリースに合わせてiTunes Connect のUIが大幅に変わっており、下記のページの方
-
-
iPhone開発本 iPhone Cool Projects
iPhone Games Projectsに続いて、iPhone Cool Projects も買っ
-
-
App Store レビュー中
8月13日にApp StoreにSubmitしたiPhoneアプリがまだIn Review状態だ。果
-
-
iOSアプリの Ad Hoc 配布の悪夢から解放される TestFlight
面倒だった Adhoc 版のやりとりを格段に楽にしてくれる TestFlight | つくる社LL
-
-
災害時のためのiPhone充電機器を探してみる
3/11(金)の2011年東北地方太平洋沖地震の後、宮城と岩手の親類と連絡が取れず、3/14(月)の