2012-01-12 6 views
0

対応する向きに対して2つの異なる画像を表示する必要があります。 Nibファイルを使用して、UIImageViewに2つの画像を追加しました。私はimage1.pngをiPadオリエンテーションポートレートで表示し、image2.pngをオリエンテーション風景モードで表示したいと考えています。いずれか1つは、UIViewControllerのNibファイルで2つのUIImageViewを追加する方法を提案できますか? iPadのnibファイルのチュートリアルをお勧めします。前もって感謝します。Nibファイルを使用してUIViewControllerで2つのUIImageViewを追加するには?

答えて

1

あなたは、ビューコントローラの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"]]; 
} 

}

私はそれはあなたに役立ちます願っています:)

+0

Dont'tその真のエンド –

+0

でYESを返し忘れて!ありがとう:) – damacri86

1

だけからUIImageViewをドラッグ図書館とあなたの視点に配置します。 しかし、1つのUIViewControllerと1つのビューを使用している場合は、コード内のイメージビューのローテーションの変更を処理する必要があります。最も簡単な方法 - 表示/非表示は方向によって異なります。

あなたはまた、唯一のUIImageViewを使用して、必要な画像に imageプロパティを変更することができます
- (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; 
    } 
} 

[imageView setImage:[UIImage imageNamed:@"image1.png"]];//or @"image2.png" 
関連する問題