0

willAnimateRotationToInterfaceOrientation:duration:duration でアニメーションを含むカスタム レイアウトを行います。問題は、デバイスが LandscapeLeft から LandscapeRight に変更された場合、インターフェイスは回転する必要がありますが、レイアウト コード、特にアニメーションは実行されないことです。ある風景から別の風景に変化していることをどのように検出できますか? self.interfaceOrientation と [[UIApplication sharedApplication] statusBarOrientation] は有効な結果を返さず、デバイスが既に回転していると考えているようです。その結果、以下は機能しません

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation) && UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) {...}
4

3 に答える 3

5

デバイスの向きを確認してから、左向きか右向きかに関するフラグを設定できます。次に、デバイスが切り替わると、それをキャッチして、好きなように処理できます。

向きを決定するには:

if([UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
{
    //set Flag for left
}
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
    //set Flag for right
}

次を使用して、デバイスが回転しているときに通知をキャッチすることもできます。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

そして、そのdetectOrientationようなメソッドを書きます:

-(void) detectOrientation 
{
    if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
    {
        //Set up left
    } else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
    {
        //Set up Right
    } else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) 
    {
        //It's portrait time!
    }   
}
于 2012-07-25T16:50:36.300 に答える
3
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
 {
   if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation ]== UIDeviceOrientationLandscapeRight)
    {
      NSLog(@"Lanscapse");
    }
   if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown )
    {
      NSLog(@"UIDeviceOrientationPortrait");
    }
 }
于 2014-12-24T09:45:20.673 に答える
1

唯一の解決策は、最後の向きの変更をキャッシュすることです。willAnimateRotationToInterfaceOrientation: が呼び出されるまでに、デバイスとインターフェイスの向きは既に更新されています。解決策は、方向が再び変更されるように設定されたときにこの値を照会できるように、各変更の最後に目的の方向を記録することです。これは私が望んでいたほどエレガントではありません (私のビュー コントローラーの別のプロパティです) が、私が知る限り、これが唯一の方法のようです。

于 2012-07-25T20:11:32.747 に答える