これらの両方のコード行の違いは何ですか?
self.view.frame = CGRectMake(0, 0, 320, 480);
self.view.superview.frame = CGRectMake(0, 0, 800, 900);
ラベルの位置が変わるため、向きが変わるときにビューフレームを変更したいのですが、ラベルを画面の中央に配置したいのですが、誰かが私を案内してくれますか?
オリエンテーションのために次のデリゲートメソッドを使用していますが、動作していません
self.view.frame
しかし、次の行で問題なく動作しています
self.view.superview.frame
次のコードを参照してください
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"LEFT");
self.view.frame = CGRectMake(100, 0, 480, 320);
NSLog(@"Show self.view.frame: %@", NSStringFromCGRect(self.view.frame));
// self.view.superview.frame = CGRectMake(-50, -70, 800, 900);
[button setFrame:CGRectMake(340, 320, 100, 30)];
}
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"RIGHT");
self.view.frame = CGRectMake(0, 0, 320, 480);
NSLog(@"Show self.view.frame: %@", NSStringFromCGRect(self.view.frame));
//self.view.superview.frame = CGRectMake(10, 90, 800, 900); //It is working if I will uncomment it
[button setFrame:CGRectMake(250, 300, 100, 30)];
}
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
self.view.frame = CGRectMake(0, 0, 320, 480);
//self.view.superview.frame = CGRectMake(0, 0, 800, 900);//It is working if I will uncomment it
[button setFrame:CGRectMake(250, 400, 100, 30)];
}
return YES;
}