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");
}
}
并且从来没有调用过任何一个 NSLog。我的观点正在旋转...