所以我有這段代碼來更改我的UIImage視圖上的圖像。在iPad和iPhone上我都會遇到一種非常奇怪的行爲。willRotateToInterfaceOrientation不工作在Universal MasterDetail應用程序
這片代碼工作完全正常,給我我想要的結果:
- (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"];
它激發甚至如果方向是景觀!
我對通用應用程序的工作經驗不足。我剛剛採用了蘋果的Master-Detail應用模板並對其進行了一些修改。這裏可能有什麼問題?提前致謝!
但它總是適合我的舊iPhone應用程序 –