2011-07-05 3 views
0

2方向をサポートするiPhoneアプリケーションを開発しています。このビューコントローラ用の2つのUIViewファイルがあります。デバイスインタフェースの向きに応じて、対応するUIViewファイルをビューコントローラに設定する必要があります。あなたは方向を変える方法について私を導くことができますか?iPhoneで向きを変更するときにViewControllerの表示を変更するにはどうすればよいですか?

答えて

3

なぜ両方の向きに2つのビューを使用しますか?ポートレートとランドスケープの両方のモードで同じようなコントロールが同じ場所に表示される場合は、コントロールの自動レジストリプロパティを設定できます。そうしないと、あなたは

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; 

か、UIDevice

UIKIT_EXTERN NSString *const UIDeviceOrientationDidChangeNotification; 

- (void)beginGeneratingDeviceOrientationNotifications;  // nestable 
- (void)endGeneratingDeviceOrientationNotifications; 
の通知を持つことができる二つのビューを使用する必要があります
2

このデリゲートをコントローラで両方の向きに渡すだけです。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 
3

あなたはすべての向きの変更を確認するためにあなたのUIViewControllerで設定することができ、次の方法を使用することができ、あなたのサポートの向きを返すために-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientationを設定していると仮定して、あなたの意見設定:

// called just before the user interface starts to rotate - my advice would be to use this method to save a copy of the current orientation. 
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

// called after the interface has finished rotating. Here, you can compare the old orientation with the new one - if you went from portrait to landscape, then update your views accordingly. 
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

これが役立つことを願っています!

関連する問題