2

誰でもこれを行う方法を知っていますか?

私はこれを考えました:

-(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 にあります。

誰にもアイデアはありますか?

乾杯、ニック。

4

3 に答える 3

20

UIDeviceOrientationDidChangeNotification( から)通知を登録してからUIDevice.h、方向の変更が必要な場合は、次のメソッドを呼び出します。

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

向きの変更を気にしなくなったら、このメソッドを呼び出します。

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

通知は該当する場合に送信され[UIDevice currentDevice].orientation、現在の向きを確認できます。

于 2009-06-15T16:29:39.663 に答える
4

ちなみに、shouldAutoRotateToInterfaceOrientation は 2.x では回転時に呼び出されていましたが、3.0 では一貫性がはるかに低くなります。他の投稿で言及されている通知は、回転の信頼できる表示のための方法です。

于 2009-06-15T20:26:30.747 に答える
1

あなたはYESから帰ってきましたがshouldAutorotateToInterfaceOrientation:、そんなつもりはなかったと思います。これは、デバイスが回転しないようにするために実装する必要がある唯一の方法です。

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

于 2009-06-15T12:36:41.633 に答える