8

画面の向きが横向きから縦向き、またはその逆に変わったときに回転アニメーションを変更または無効にするにはどうすればよいですか?

4

3 に答える 3

16

はい、すべてをばらばらにすることなく、アニメーションを無効にすることができます。

次のコードは、他のアニメーションや向きのコードをいじることなく、「ブラック ボックス」の回転アニメーションを無効にします。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [UIView setAnimationsEnabled:YES];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    [UIView setAnimationsEnabled:NO];
  /* Your original orientation booleans*/
}

UIViewController に配置すると、すべてがうまくいくはずです。iOS の不要なアニメーションにも同じ方法を適用できます。

あなたのプロジェクトの幸運を祈ります。

于 2011-06-09T12:07:27.793 に答える
8

ビュー コントローラを回転させたくない場合は、shouldAutoRotateToInterface ビュー コントローラ メソッドをオーバーライドして、サポートしたくない方向に対して false を返すだけです...ここにリファレンスがあります

他の方法で回転を処理したいだけの場合は、上記のメソッドで false を返し、そのように UIDeviceOrientationDidChangeNotification に登録できます。

    NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
       selector:@selector(handleOrientationDidChange:)
           name:UIDeviceOrientationDidChangeNotification
         object:nil];

通知を受け取ったら、好きなことを何でもできます...

于 2010-04-29T16:05:52.883 に答える