我将方向设置为RootViewController中剩余的横向,但在viewDidLoad或viewWillAppear中,VC的视图边界不是旋转的。在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
答案 0 :(得分:1)
您可以在方向更改后设置框架:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
答案 1 :(得分:0)
我认为它应该在这个功能中
- (void)viewDidLayoutSubviews {}
Apple的医生说