2012-01-12 79 views
0

我必須爲相應的方向顯示兩個不同的圖像。我通過使用Nib文件在一個UIImageView中添加了兩個圖像。我想在iPad方向縱向中顯示image1.png,並且想要在方向橫向模式下顯示image2.png。任何人都可以請我建議如何在UIViewController中通過Nib文件添加兩個UIImageView?請爲iPad筆尖文件提供任何教程。提前致謝。如何使用Nib文件在UIViewController中添加兩個UIImageView?

回答

1

你必須改變的UIImageView的圖像中的視圖控制器的shouldAutorotate方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) && (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) { 
    // Set image in landscape mode 
    [imageView setImage:[UIImage imageNamed:@"image1.png"]]; 
} 
else 
    // Set image in portrait mode 
    [imageView setImage:[UIImage imageNamed:@"image2.png"]]; 
} 

}

我希望它能幫助你:)

+0

Dont't忘記在結束 – 2012-01-12 14:31:47

+0

其真正返回YES!謝謝 :) – damacri86 2012-01-16 12:05:11

1

剛剛從拖動的UIImageView圖書館並放入您的視野。 但是,如果您使用的是一個UIViewController和一個視圖,則需要處理代碼中的圖像視圖旋轉更改。最簡單的方法 - 顯示/隱藏取決於方向。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
    UIImageView *landscapeimageView = nil; 
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){ 
     landscapeImageView.hidden = NO; 
     portretOmageView.hidden = YES; 
    } 
    else{ 
     landscapeImageView.hidden = YES; 
     portretOmageView.hidden = NO; 
    } 
} 

您也可以只使用一個的UIImageView和image屬性更改爲需要的圖像:

[imageView setImage:[UIImage imageNamed:@"image1.png"]];//or @"image2.png" 
相關問題