如果需要旋转的ViewController 使用了UINavigationController,对UINavigationController进行如下扩展
@implementationUINavigationController(shouldAutorotate)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return(interfaceOrientation ==UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{returnself.topViewController.shouldAutorotate;
}
-(NSUInteger)supportedInterfaceOrientations
{returnself.topViewController.supportedInterfaceOrientations;
}@end
需要旋转的ViewController设置
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{returnYES;
}-(BOOL)shouldAutorotate
{returnYES;
}-(NSUInteger)supportedInterfaceOrientations
{returnUIInterfaceOrientationMaskAll;
}
其他不需要旋转的 ViewController设置,建议添加BaseViewController统一控制
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return(interfaceOrientation ==UIInterfaceOrientationPortrait);
}-(BOOL)shouldAutorotate
{returnNO;
}-(NSUInteger)supportedInterfaceOrientations
{returnUIInterfaceOrientationPortrait;
}