以UINavigationController为根视图,在UINavigationController的子类中做如下重写
A画面中可以做任何旋转操作设置代码如下:
在A画面在横屏的状态下push出B画面,B画面做如下设置
此时B画面显示时,屏幕转为竖屏,但是问题是UINavigationBar依然保持着在A画面的位置,竖在屏幕上。请问这种问题怎么解决。看了好多网上写的解决办法。说是好用但是我这都没有效果,是我哪个地方设置的有问题么。
#import "MyNavigationViewController.h"
@interface MyNavigationViewController ()
@end
@implementation MyNavigationViewController
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations {
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
A画面中可以做任何旋转操作设置代码如下:
// 画面の回転制御
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
在A画面在横屏的状态下push出B画面,B画面做如下设置
// 画面の回転制御
- (void)viewWillAppear:(BOOL)animated
{
self.view.transform = CGAffineTransformIdentity;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;//(获取当前电池条动画改变的时间)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
if (orientation == UIInterfaceOrientationLandscapeLeft) {
self.view.transform = CGAffineTransformMakeRotation(M_PI);
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
self.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
} else {
self.view.transform = CGAffineTransformIdentity;
}
[UIView commitAnimations];
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
此时B画面显示时,屏幕转为竖屏,但是问题是UINavigationBar依然保持着在A画面的位置,竖在屏幕上。请问这种问题怎么解决。看了好多网上写的解决办法。说是好用但是我这都没有效果,是我哪个地方设置的有问题么。