2009-06-15 4 views
2

誰でもこれを行う方法を知っていますか?デバイスを自動回転させずにiPhoneで回転を検出するにはどうすればよいですか?

私はこれを考えた:

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

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
} 

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
} 

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
} 

- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
} 

- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration { 
} 

が回転からデバイスを防ぐこと(すべてのオーバーライドが私のUIViewControllerの方法を回転させると、スーパークラスを呼び出していない)が、私はそれが実際に回転を実行のUIViewControllerではありません恐れています。

私のUIViewControllerは、UINavigationControllerにあります。

誰もが考えている?

乾杯、 ニック。

+1

実際に使用する必要があるものだけ、それらの空のデリゲートメソッドをすべてオーバーライドする必要はありません。呼び出し側は、定義したかどうかにかかわらず、呼び出す前にサブクラスが特定のメソッドに応答するかどうかをテストする必要があります。それは単に代理人が働く方法です。 –

答えて

20

あなたは(UIDevice.hから)通知UIDeviceOrientationDidChangeNotificationのために登録して、あなたが向きの変更を気にする場合、このメソッドを呼び出すことができます。

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

あなたはもはや、向きの変更を気にしない、このメソッドを呼び出すと:

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 

該当する場合は通知が送信され、[UIDevice currentDevice].orientationにチェックすると現在の向きがわかります。

+0

ありがとう - これは私が後にしたものです! –

+0

悪い副作用は、デバイスがもうスリープ状態にならないということです。 – drvdijk

1

YESshouldAutorotateToInterfaceOrientation:から返信していますが、これは意味がないと思われます。これは、デバイスの回転を防ぐために実装する必要がある唯一の方法です。

デバイスの現在の向きを取得する場合、[[UIDevice currentDevice] orientation]を使用できます。

+0

ねえ、ありがとう - あなたの提案に感謝! [[UIDevice currentDevice] orientation]は現在の方向を取得しますが、電話機が自動回転していなければこれを検出する必要があります。 shouldAutorotateToInterfaceOrientationからNOを返すと、デリゲート関数が呼び出されないので、ローテーションが発生したときに検出する能力が失われます。 他に誰かがアイデアを持っていますか? 乾杯、 ニック。 –

4

sideAutoRotateToInterfaceOrientationは、2.xでローテーションするときに使用されていましたが、3.0ではそれほど一貫性がありませんでした。他の投稿に記載されている通知は、信頼性の高いローテーションの表示方法です。

+0

ヒントKendallのヒント! N –

関連する問題