iOS 6 のAuto Rotation
-
Upload
yuichi-fujishige -
Category
Technology
-
view
1.560 -
download
1
description
Transcript of iOS 6 のAuto Rotation
![Page 1: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/1.jpg)
iOS 6 のAuto Rotation
2012.12.01ふじしげ ゆういち@nakiwo
![Page 2: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/2.jpg)
• ふじしげ ゆういち• @nakiwo• 株式会社フィードテイラーhttp://feedtailor.jp/
Book+
そら案内
Slidrs
![Page 3: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/3.jpg)
• ふじしげ ゆういち• @nakiwo• http://www.nakiwo.com/
洞窟物語
めがね(Mac AppStore)
![Page 4: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/4.jpg)
![Page 5: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/5.jpg)
![Page 6: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/6.jpg)
![Page 7: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/7.jpg)
![Page 8: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/8.jpg)
今日のテーマ
• iOS 6でのUIViewController Auto Rotation
• iOS 6で仕様が大幅変更• iOS 6での仕様を把握する
![Page 9: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/9.jpg)
iOS 5UIViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
By default, this method returns YES for the UIInterfaceOrientationPortrait orientation only.
![Page 10: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/10.jpg)
iOS 6UIViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
By default, this method returns YES for the UIInterfaceOrientationPortrait orientation only.
• deprecated•呼ばれません
![Page 11: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/11.jpg)
UIViewController
UIViewControllerUIViewController
UIViewControllerUIViewController
![Page 12: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/12.jpg)
UIViewController
UIViewControllerUIViewController
UIViewControllerUIViewController
誰が正解?
![Page 13: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/13.jpg)
UIInterfaceOrientationMasktypedef enum { UIInterfaceOrientationMaskPortrait, UIInterfaceOrientationMaskLandscapeLeft, UIInterfaceOrientationMaskLandscapeRight, UIInterfaceOrientationMaskPortraitUpsideDown, UIInterfaceOrientationMaskLandscape, UIInterfaceOrientationMaskAll, UIInterfaceOrientationMaskAllButUpsideDown,} UIInterfaceOrientationMask;
※ビットマスク
![Page 14: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/14.jpg)
関係者
UIApplication UIViewController
![Page 15: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/15.jpg)
関係者
UIApplication UIViewController
window.rootViewController またはトップのpresentedViewController(モーダル)
![Page 16: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/16.jpg)
関係者
UIApplication UIViewController
window.rootViewController またはトップのpresentedViewController(モーダル)
![Page 17: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/17.jpg)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
![Page 18: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/18.jpg)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
![Page 19: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/19.jpg)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
![Page 20: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/20.jpg)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
![Page 21: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/21.jpg)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
![Page 22: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/22.jpg)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
bit and
![Page 23: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/23.jpg)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
bit and
![Page 24: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/24.jpg)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
bit and
対応回転方向決定
![Page 25: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/25.jpg)
関係者
UIApplication
UIInterfaceOrientationMask
![Page 26: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/26.jpg)
UIApplication
UIApplicationDelegate- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
上記メソッド未実装の時は次のメソッドが呼ばれる
UIApplication- (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window
![Page 27: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/27.jpg)
UIApplication- (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window
The default implementation of this method returns the app’s default set of supported interface orientations, as defined in the UIInterfaceOrientation key of the Info.plist file.
If the file does not contain that key, this method returns all interface orientations for the iPad idiom and returns all interface orientations except the portrait upside-down orientation for the iPhone idiom.
![Page 28: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/28.jpg)
UIApplication- (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window
The default implementation of this method returns the app’s default set of supported interface orientations, as defined in the UIInterfaceOrientation key of the Info.plist file.
If the file does not contain that key, this method returns all interface orientations for the iPad idiom and returns all interface orientations except the portrait upside-down orientation for the iPhone idiom.
Info.plistにUISupportedInterfaceOrientations有
UISupportedInterfaceOrientationsの値
Info.plistにUISupportedInterfaceOrientations無
iPhone UIInterfaceOrientationMaskAllButUpsideDowniPadUIInterfaceOrientationMaskAll
![Page 29: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/29.jpg)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
bit and
対応回転方向決定
![Page 30: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/30.jpg)
UIViewController
UIInterfaceOrientationMask
window.rootViewController またはトップのpresentedViewController(モーダル)
![Page 31: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/31.jpg)
UIViewController
- (BOOL)shouldAutorotateAuroRotateするかどうか(default=YES)
- (NSUInteger)supportedInterfaceOrientations
defaultiPhone UIInterfaceOrientationMaskAllButUpsideDowniPad UIInterfaceOrientationMaskAll
![Page 32: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/32.jpg)
UIViewController
注意点UIViewControllerUIViewController
UIViewControllerUIViewController
![Page 33: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/33.jpg)
UIViewController
注意点UIViewControllerUIViewController
UIViewControllerUIViewController
聴かれるのは一番親だけ (水色)
![Page 34: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/34.jpg)
UIViewController (UINavigationController,UITabBarController)
注意点UIViewControllerUIViewController
UIViewControllerUIViewController
![Page 35: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/35.jpg)
Tips
![Page 36: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/36.jpg)
iOS 5でPortrait専用だったのにiOS 6で回転してしまう...
![Page 37: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/37.jpg)
iOS 5でPortrait専用だったのにiOS 6で回転してしまう...
UIApplicationDelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ return UIInterfaceOrientationMaskPortrait;}
![Page 38: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/38.jpg)
Navigationの子でshouldAutorotateToInterfaceOrientationを
使っていたが呼ばれない....
![Page 39: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/39.jpg)
Navigationの子でshouldAutorotateToInterfaceOrientationを
使っていたが呼ばれない....
UINavigationControllerのサブクラスを作って...
- (NSUInteger)supportedInterfaceOrientations{ NSUInteger supportedInterfaceOrientations; = [self.topViewController supportedInterfaceOrientations];
return supportedInterfaceOrientations;}
![Page 40: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/40.jpg)
iOS 5もサポートしないと...
![Page 41: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/41.jpg)
iOS 5もサポートしないと...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ // 今まで通りに書く return ...;}
- (NSUInteger)supportedInterfaceOrientations{ NSUInteger supportedInterfaceOrientations = 0;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait]) supportedInterfaceOrientations |= UIInterfaceOrientationMaskPortrait;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown]) supportedInterfaceOrientations |= UIInterfaceOrientationMaskPortraitUpsideDown;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft]) supportedInterfaceOrientations |= UIInterfaceOrientationMaskLandscapeLeft;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight]) supportedInterfaceOrientations |= UIInterfaceOrientationMaskLandscapeRight;
return supportedInterfaceOrientations;}
![Page 42: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/42.jpg)
おまけ
![Page 43: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/43.jpg)
おまけ• 複数法対応のViewControllerをモーダルで出す時、初期方向を変えたい
• 例:動画プレイヤー縦横対応しているが、初期では横にしたい。
![Page 44: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/44.jpg)
おまけ• 複数法対応のViewControllerをモーダルで出す時、初期方向を変えたい
• 例:動画プレイヤー縦横対応しているが、初期では横にしたい。
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationLandscapeRight;}
![Page 45: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/45.jpg)
• View Controller Programming Guide for iOS
> Supporting Multiple Interface Orientations
![Page 46: iOS 6 のAuto Rotation](https://reader033.fdocuments.net/reader033/viewer/2022060122/5595d3361a28abe82b8b46e0/html5/thumbnails/46.jpg)
おわり