-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
在每个viewcontroller中写以下的代码支持横竖屏:
- (BOOL)shouldAutorotate{
return NO;/返回YES 支持旋转
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;/
UIInterfaceOrientationMaskPortrait(支持竖屏)
UIInterfaceOrientationMaskLandscapeLeft(支持home键向左)
UIInterfaceOrientationMaskLandscapeRight (支持home键向右)
UIInterfaceOrientationMaskPortraitUpsideDown (支持home键在上)
UIInterfaceOrientationMaskLandscape(支持横屏)
UIInterfaceOrientationMaskAll (支持各个方向)
UIInterfaceOrientationMaskAllButUpsideDown(支持除了home键在上方的)
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
如果根视图为UITabBarController 在tabbar的子类写如下代码
- (BOOL)shouldAutorotate
{
//返回顶层视图的设置(顶层控制器需要覆盖shouldAutorotate方法)
NavRootViewController *nav = (NavRootViewController *)[self.viewControllers objectAtIndex:self.selectedIndex];
return nav.topViewController.shouldAutorotate;
//}
//
//return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
NavRootViewController *nav = [self.viewControllers objectAtIndex:self.selectedIndex];
return nav.topViewController.preferredInterfaceOrientationForPresentation;
}
//6.0之后系统调用该方法
-(NSUInteger)supportedInterfaceOrientations
{
//返回顶层视图支持的旋转方向
NavRootViewController *nav = (NavRootViewController *)[self.viewControllers objectAtIndex:self.selectedIndex];
return nav.topViewController.supportedInterfaceOrientations;
// return 0;
}
以下是参考文档
{
}
//6.0之后系统调用该方法
-(BOOL)shouldAutorotate
{
//系统会调用跟视图的旋转控制方法,所以我们将跟视图将控制条件交给顶层视图(顶层视图即我们需要控制的视图)
系统调用该方法
}
//6.0之后系统调用该方法,应该支持的方向
-(NSUInteger)supportedInterfaceOrient
{
}
三、跟视图为UITabBarController(在UITabBarController中设置)
//6.0之后系统调用该方法
-(BOOL)shouldAutorotate
{
}
//6.0之后系统调用该方法
-(NSUInteger)supportedInterfaceOrient
{
}
四、跟视图为MMDrawerController
//6.0一下系统调用该方法
-(BOOL)shouldAutorotateToInterf
{
}
//6.0之后系统调用该方法
-(BOOL)shouldAutorotate
{
}
//6.0之后系统调用该方法
-(NSUInteger)supportedInterfaceOrient
{
}
五、presentViewController视图控制