因为rootViewController是navigationController,所以我们不仅仅改变要控制器自身的frame,还要改变navigationController.view.bounds
_x =self.navigationController.view.bounds.origin.x;
_y =self.navigationController.view.bounds.origin.y;
_width =self.view.frame.size.width;
_height =self.view.frame.size.height;
CGFloat duration = [UIApplicationsharedApplication].statusBarOrientationAnimationDuration;
[UIViewanimateWithDuration:durationanimations:^{
// [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];
self.navigationController.view.transform =CGAffineTransformMakeRotation(M_PI_2);
self.navigationController.view.bounds = CGRectMake(self.navigationController.view.bounds.origin.x,self.navigationController.view.bounds.origin.y,self.view.frame.size.height,self.view.frame.size.width);
self.view.frame =CGRectMake(0,0,self.view.frame.size.height,self.view.frame.size.width);
}];
这样设置以后发现状态栏并没有旋转过来,也就是说
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];
这句代码在iOS中已经没有作用了。无奈之下,只能把状态栏给隐藏。
[[UIApplicationsharedApplication]setStatusBarHidden:YES];这句代码在iOS9 也不管用了。
管用的方法:
-(BOOL)prefersStatusBarHidden
{
returnYES;
}
-(void)viewWillDisappear:(BOOL)animated
{
CGFloat duration = [UIApplicationsharedApplication].statusBarOrientationAnimationDuration;
[UIViewanimateWithDuration:duration animations:^{
// [[UIApplicationsharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
self.navigationController.view.transform=CGAffineTransformIdentity;
self.navigationController.view.frame = CGRectMake(_x,_y, _width,_height);
}];
}