Utilityテンプレートで横向きアプリを作る方法

iPhone Programming Tutorial - Landscape-Only View-Based Applicationを参考にして、Utilityテンプレートでも横向き専用にできたのでメモ。

info.plist

info.plistに

UIInterfaceOrientation
UIInterfaceOrientationLandscapeRight

を追加します。

RootViewController.m

まず、

// Override to allow orientations other than the default portrait orientation.

の塊をさがして、「/*」、「*/」を削除して有効化。


そして、

return (interfaceOrientation == UIInterfaceOrientationPortrait);

return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

に変更します。


ここまでで基本的には横向きUIになるはずですが、Utilityテンプレートの場合は、もう2箇所の修正が必要です。

裏面のNavigationBarの大きさの調整

UINavigationBar *aNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];

UINavigationBar *aNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 480.0, 44.0)];

MainWindow.xibに属するViewの始点がおかしくなっているので、RootViewController.mで修正。

 - (void)viewDidLoad {

[super viewDidLoad];

の後に

[self.view setFrame:CGRectMake(0, 0, 480, 300)];

を追加します。


あとは、InterfaceBuilderで.xibファイルたちを横向きにしてやれば、Utilityテンプレートを使った横向き専用UIの完成です。

                                              • -

関連エントリー
プログラム未経験の僕が初めて作ったiPhoneアプリが2月16日に発売されます!というわけで使用した参考資料等のまとめ。
SingingCatをリリースして思ったこと → みんなiPhoneアプリを作ればいい。
App Storeに表示される「リリース日」のまとめ