0

以下のコードは、2 つの可能な横向きのいずれかで正常に動作しますが、デバイス 180 を別の横向きにすると、読み込む画像は下にあるビューと比較してボトムアップになります。

だから私が持っているのは、ストーリーボードで作成されたビューの上にコードで作成されたビュー(画面全体にオーバーレイし、その上に画像がある)です。

質問は次のとおりです。半透明のオーバーレイ ビューの左上隅を、下にあるビューの左上隅と同じ場所に描画できますか? . 基礎となるビューと向きを変えるには、オーバーレイ ビューが必要です。

ここでは、ビューで画面全体をカバー (オーバーレイ) します。

self.overlayView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,[[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height)];

次に、ビューに表示したい画像を読み込みます。

UIImage* image = [UIImage  imageNamed:@"image.png"];

ここで画像を設定します

[overlayView  setImage:image];

私は運がないオリエンテーションですべてを試しました。私のアプリは 360° 自動回転するので、ステータス バーは常に一番上に表示されます。

これが誰かにとって意味があることを願っています!

編集:使用されているコード全体は次のとおりです

UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow;
self.overLayView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,[[UIScreen  mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height)];

[overLayView setImage:[UIImage imageNamed:@"someImage1.png"]];
overLayView.tag = 1; //Used to remove the view in another function
overLayView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5]; //Semi transparent

CGRect viewFrames = CGRectMake([[UIScreen mainScreen] bounds].size.width - 100, [[UIScreen mainScreen] bounds].size.height - 100, 75, 75);

self.exitHelpView = [[UIImageView alloc] initWithFrame:viewFrames];
[self.exitHelpView setImage:[UIImage imageNamed:@"imageOfXUsedToCloseWhenClicked.png"]];
self.exitHelpView.tag = 2; //Used to remove the view in another function

[keyWindow addSubview:overLayView]; //The view covering the whole screen
[keyWindow addSubview:self.exitHelpView]; //Image of an X 

そして私の.hファイルで

@property (strong, nonatomic) IBOutlet UIImageView* overLayView;
@property (strong, nonatomic) IBOutlet  UIImageView* exitHelpView;
4

1 に答える 1

1

UIWindow に追加したものは、デバイスの回転を考慮しません。これは UIViewController の大きな特徴の 1 つで、回転イベントに自動的に応答します。ビューを UIViewController のビュー階層に追加しても機能する方法が見つからない場合は、回転イベントを手動でリッスンし、UIView の位置をプログラムで調整する必要があります。

于 2013-06-25T23:08:15.913 に答える