所以我有这个代码来改变我的 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 并对其进行了一些修改。这里有什么问题?提前致谢!