したがって、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 を少しだけ変更しました。ここで何が問題になる可能性がありますか?前もって感謝します!