ViewControllerA
viewDidLoad
次のようなボタンをプログラムで作成するメソッドがあります。
self.cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.cancelButton.frame = CGRectMake(330, 625, 125, 30);
[self.cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[self.cancelButton sizeToFit];
[self.cancelButton addTarget:self action:@selector(cancelButton:) forControlEvents:UIControlEventTouchUpInside];
[self.cancelButton setNeedsDisplay];
[self.view addSubview:self.cancelButton];
私も持ってい- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return YES;}
ます。
デバイスを横向きに回転させたときに、ボタン枠を変更したい。上記の方法をチェックinterfaceOrientation
してshouldAutorotate...
、フレームを設定しようとしました。if (UIInterfaceOrientationLandscapeLeft == [[UIApplication sharedApplication] statusBarOrientation])
そこでフレームを実行してリセットしようとしました。これはどれも機能していません。助言がありますか?
編集
変化をもたらさない別の試みを次に示します。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
self.cancelButton.frame = CGRectMake(15, 15, 300, 50);
}
}
だから私はやってみました:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait
|| toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
NSLog(@"Portait");
} else {
NSLog(@"Landscape");
}
}
そして、どちらの NSLogs も呼び出されません。視界がぐるぐるしてるけど…