[英]How to add two UIImageView in UIViewController using Nib file?
我必須為相應的方向顯示兩個不同的圖像。 我使用Nib文件在一個UIImageView中添加了兩個圖像。 我想表明image1.png
在iPad的方向縱向和要顯示image2.png
取向橫向模式。 任何人都可以建議我如何在UIViewController
添加兩個UIImageView by Nib文件? 請為iPad nib文件推薦任何教程。 提前致謝。
您必須在視圖控制器的shouldAutorotate方法中更改UIImageView的圖像:
- (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"]];
}
}
我希望它對你有幫助:)
只需將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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.