1

iOS4.2 アプリを起動すると、webview が読み込まれるまで表示される画像が表示されます。webview が読み込まれた後、その画像は非表示に設定されます。次のことを行うにはどうすればよいですか: 縦向きの場合は、DefaultPortrait.png を表示します。

デバイスが縦長の場合、表示

self.view.backgroundColor = [UIColor blackColor];
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"Default2.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];

また

デバイスが横向きの場合は表示

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 480f, 320.0f);
myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"Default2L.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
4

3 に答える 3

3

を使用しdidRotateFromInterfaceOrientationてコードを実装できます。ここで、向きが縦向きから変更されるときに、デバイスが横向きモードのときに表示したいコードを実装し、その逆も同様です。問題が解決することを願っています。

    - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    if ((fromInterfaceOrientation == UIInterfaceOrientationPortrait) || (fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) {

        // your method for landscape..

    }
    if ((fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) || (fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) {

        //your method for portrait
    }
}
于 2011-07-30T04:27:02.613 に答える
0

最初にこれを使用して、現在の向きを取得できます。

   UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation] 

そして、これを使用します:

 if ((currentOrientation == UIInterfaceOrientationPortrait) || (currentOrientation == UIInterfaceOrientationPortraitUpsideDown)) {
self.view.backgroundColor = [UIColor blackColor];
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"Default2.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];

    }
   else if ((currentOrientation == UIInterfaceOrientationLandscapeRight) || (currentOrientation == UIInterfaceOrientationLandscapeLeft)) {
self.view.backgroundColor = [UIColor blackColor];
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"Default2.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
}
于 2011-07-30T04:36:52.823 に答える
0

両方のモードで同じ画像を表示する場合は、最初にアプリ デリゲート ファイルでブール型変数を宣言し、アプリ デリゲート .m ファイルで定義します。ポートレート モードの場合は変数 true で、ランドスケープ モードの場合は false です。今

_(void)viewDidLoad{
              if (Boolean variable == TRUE ){
                                         //display portrait mode }
                 else 
                      //display landscape mode

}

于 2011-07-30T05:26:18.330 に答える