iOS 6 のAuto Rotation

46
iOS 6 Auto Rotation 2012.12.01 ふじしげ ゆういち @nakiwo

description

第47回 Cocoa勉強会関西 発表資料。

Transcript of iOS 6 のAuto Rotation

Page 1: iOS 6 のAuto Rotation

iOS 6 のAuto Rotation

2012.12.01ふじしげ ゆういち@nakiwo

Page 2: iOS 6 のAuto Rotation

• ふじしげ ゆういち• @nakiwo• 株式会社フィードテイラーhttp://feedtailor.jp/

Book+

そら案内

Slidrs

Page 3: iOS 6 のAuto Rotation

• ふじしげ ゆういち• @nakiwo• http://www.nakiwo.com/

洞窟物語

めがね(Mac AppStore)

Page 4: iOS 6 のAuto Rotation
Page 5: iOS 6 のAuto Rotation
Page 6: iOS 6 のAuto Rotation
Page 7: iOS 6 のAuto Rotation
Page 8: iOS 6 のAuto Rotation

今日のテーマ

• iOS 6でのUIViewController Auto Rotation

• iOS 6で仕様が大幅変更• iOS 6での仕様を把握する

Page 9: iOS 6 のAuto Rotation

iOS 5UIViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

By default, this method returns YES for the UIInterfaceOrientationPortrait orientation only.

Page 10: iOS 6 のAuto Rotation

iOS 6UIViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

By default, this method returns YES for the UIInterfaceOrientationPortrait orientation only.

• deprecated•呼ばれません

Page 11: iOS 6 のAuto Rotation

UIViewController

UIViewControllerUIViewController

UIViewControllerUIViewController

Page 12: iOS 6 のAuto Rotation

UIViewController

UIViewControllerUIViewController

UIViewControllerUIViewController

誰が正解?

Page 13: iOS 6 のAuto Rotation

UIInterfaceOrientationMasktypedef enum { UIInterfaceOrientationMaskPortrait, UIInterfaceOrientationMaskLandscapeLeft, UIInterfaceOrientationMaskLandscapeRight, UIInterfaceOrientationMaskPortraitUpsideDown, UIInterfaceOrientationMaskLandscape, UIInterfaceOrientationMaskAll, UIInterfaceOrientationMaskAllButUpsideDown,} UIInterfaceOrientationMask;

※ビットマスク

Page 14: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

Page 15: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

window.rootViewController またはトップのpresentedViewController(モーダル)

Page 16: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

window.rootViewController またはトップのpresentedViewController(モーダル)

Page 17: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

Page 18: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

Page 19: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

UIInterfaceOrientationMask UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

Page 20: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

UIInterfaceOrientationMask UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

Page 21: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

UIInterfaceOrientationMask UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

Page 22: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

UIInterfaceOrientationMask UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

bit and

Page 23: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

UIInterfaceOrientationMask UIInterfaceOrientationMask

UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

bit and

Page 24: iOS 6 のAuto Rotation

関係者

UIApplication UIViewController

UIInterfaceOrientationMask UIInterfaceOrientationMask

UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

bit and

対応回転方向決定

Page 25: iOS 6 のAuto Rotation

関係者

UIApplication

UIInterfaceOrientationMask

Page 26: iOS 6 のAuto Rotation

UIApplication

UIApplicationDelegate- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

上記メソッド未実装の時は次のメソッドが呼ばれる

UIApplication- (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window

Page 27: iOS 6 のAuto Rotation

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

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

関係者

UIApplication UIViewController

UIInterfaceOrientationMask UIInterfaceOrientationMask

UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

bit and

対応回転方向決定

Page 30: iOS 6 のAuto Rotation

UIViewController

UIInterfaceOrientationMask

window.rootViewController またはトップのpresentedViewController(モーダル)

Page 31: iOS 6 のAuto Rotation

UIViewController

- (BOOL)shouldAutorotateAuroRotateするかどうか(default=YES)

- (NSUInteger)supportedInterfaceOrientations

defaultiPhone UIInterfaceOrientationMaskAllButUpsideDowniPad UIInterfaceOrientationMaskAll

Page 32: iOS 6 のAuto Rotation

UIViewController

注意点UIViewControllerUIViewController

UIViewControllerUIViewController

Page 33: iOS 6 のAuto Rotation

UIViewController

注意点UIViewControllerUIViewController

UIViewControllerUIViewController

聴かれるのは一番親だけ (水色)

Page 34: iOS 6 のAuto Rotation

UIViewController (UINavigationController,UITabBarController)

注意点UIViewControllerUIViewController

UIViewControllerUIViewController

Page 35: iOS 6 のAuto Rotation

Tips

Page 36: iOS 6 のAuto Rotation

iOS 5でPortrait専用だったのにiOS 6で回転してしまう...

Page 37: iOS 6 のAuto Rotation

iOS 5でPortrait専用だったのにiOS 6で回転してしまう...

UIApplicationDelegate

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ return UIInterfaceOrientationMaskPortrait;}

Page 38: iOS 6 のAuto Rotation

Navigationの子でshouldAutorotateToInterfaceOrientationを

使っていたが呼ばれない....

Page 39: iOS 6 のAuto Rotation

Navigationの子でshouldAutorotateToInterfaceOrientationを

使っていたが呼ばれない....

UINavigationControllerのサブクラスを作って...

- (NSUInteger)supportedInterfaceOrientations{ NSUInteger supportedInterfaceOrientations; = [self.topViewController supportedInterfaceOrientations];

return supportedInterfaceOrientations;}

Page 40: iOS 6 のAuto Rotation

iOS 5もサポートしないと...

Page 41: iOS 6 のAuto Rotation

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

おまけ

Page 43: iOS 6 のAuto Rotation

おまけ• 複数法対応のViewControllerをモーダルで出す時、初期方向を変えたい

• 例:動画プレイヤー縦横対応しているが、初期では横にしたい。

Page 44: iOS 6 のAuto Rotation

おまけ• 複数法対応のViewControllerをモーダルで出す時、初期方向を変えたい

• 例:動画プレイヤー縦横対応しているが、初期では横にしたい。

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationLandscapeRight;}

Page 45: iOS 6 のAuto Rotation

• View Controller Programming Guide for iOS

> Supporting Multiple Interface Orientations

Page 46: iOS 6 のAuto Rotation

おわり