我在 RootViewController 中将方向设置为横向,但在 viewDidLoad 或 viewWillAppear 中,VC 的 View 边界没有旋转。在 viewDidAppear 中,它有一个正确的框架。我觉得viewDidAppear里面不是一个好地方,怎么办?
@implementation RootViewController
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = self.view.bounds;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGRect frame = self.view.bounds;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect frame = self.view.bounds;
}
#pragma mark - Orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}
//for iOS 6 or later
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
@end
日志显示:
viewDidLoad,x = 0.000000, y = 0.000000,w = 300.000000 h = 480.000000
viewWillAppear:,x = 0.000000, y = 0.000000,w = 300.000000 h = 480.000000
viewDidAppear:,x = 0.000000, y = 0.000000,w = 480.000000 h = 300.000000
最佳答案
您可以在方向改变后设置框架:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
关于objective-c - 我应该在哪里设置 ViewController 中的 subview 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13641641/