0

したがって、UIImageビューで画像を変更するためのこのコードがあります。そして、iPad と iPhone の両方で非常に奇妙な動作が発生します。

このコードは完全に正常に機能し、必要な結果が得られます。

- (void)viewWillAppear:(BOOL)animated {
    if ([[UIApplication sharedApplication] statusBarOrientation] ==  UIInterfaceOrientationLandscapeRight||
        [[UIApplication sharedApplication] statusBarOrientation] ==  UIInterfaceOrientationLandscapeLeft) {
        self.backgroundView.image = [UIImage imageNamed:@"roadBackgroundLandscape.png"];
    } 
    if ([[UIApplication sharedApplication] statusBarOrientation] ==  UIInterfaceOrientationPortrait||
        [[UIApplication sharedApplication] statusBarOrientation] ==  UIInterfaceOrientationPortraitUpsideDown) {
        self.backgroundView.image = [UIImage imageNamed:@"roadBackgroundPortrait.png"];
    }
}

しかし、まったく同じコードを別のメソッドに配置しても、望ましい結果が得られません! ポートレートの写真を取り、それをランドスケープに使用するだけです。そして、縦向きの場合は、まったく別の画像を使用しています!

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

    if ([[UIApplication sharedApplication] statusBarOrientation] ==  UIInterfaceOrientationLandscapeRight||
        [[UIApplication sharedApplication] statusBarOrientation] ==  UIInterfaceOrientationLandscapeLeft) {
        self.backgroundView.image = [UIImage imageNamed:@"roadBackgroundLandscape.png"];
    } 
    else if ([[UIApplication sharedApplication] statusBarOrientation] ==  UIInterfaceOrientationPortrait||
        [[UIApplication sharedApplication] statusBarOrientation] ==  UIInterfaceOrientationPortraitUpsideDown) {
        self.backgroundView.image = [UIImage imageNamed:@"roadBackgroundPortrait.png"];
    }

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

行にブレークポイントを設定すると、向きが横になっていてもself.backgroundView.image = [UIImage imageNamed:@"roadBackgroundPortrait.png"];発火します!

ユニバーサル アプリでの作業経験はあまりありません。Apple の Master-Detail App Template を少しだけ変更しました。ここで何が問題になる可能性がありますか?前もって感謝します!

4

1 に答える 1

1

toInterfaceOrientationを使用して、 willRotateToInterfaceOrientation メソッドで向きを決定します。この関数が呼び出されたとき、statusBarOrientationはまだ古いものです。

参考までに、デバイスの回転が変更された後にdidRotateFromInterfaceOrientationが呼び出されます。ここでstatusBarOrientationを照会すると、正しいはずです。

于 2012-09-10T17:50:47.557 に答える