问题描述
如何将某些视图控制器设置为横向和纵向并且仅设置为横向?谢谢.
How can I set certain view controller to be landscape and portrait and certain to be landscape only? Thanks .
推荐答案
步骤1.创建UINavigationcontroller的子类,命名为CustomNavController步骤2.在AppdDelegate中初始化CustomNavController而不是UINavigationController.
Step 1. Create a subclass of UINavigationcontroller named like CustomNavControllerStep 2. initialise CustomNavController instead of UINavigationController in AppdDelegate.
第3步.在CustomNavController中重写UINavigationController的以下方法
Step 3. override following method of UINavigationController in CustomNavController
-(NSUInteger) supportedInterfaceOrientations
{
if([NSStringFromClass([[[self viewControllers] lastObject] class]) isEqualToString:@"ViewAsset"]){
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return YES;
}
其中ViewAsset是在两种模式下都需要的类的名称.
where ViewAsset is name of class which you need in both mode.
更多有趣的教程,请查看 https://appengineer.in/
for more interesting tutorials check out https://appengineer.in/
这篇关于如何将某些视图控制器设置为横向和纵向并且仅设置为横向? (iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!