How can I set certain view controller to be landscape and portrait and certain to be landscape only? Thanks .
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Step 1. Create a subclass of UINavigationcontroller named like CustomNavController Step 2. initialise CustomNavController instead of UINavigationController in AppdDelegate.
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;
}
where ViewAsset is name of class which you need in both mode.
for more interesting tutorials check out https://appengineer.in/
回答2:
1) Select the "device orientations" that you want in your project from the "Deployment Info" in the "General" tab.
2) In your view controller class, use this code:
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
3) For view controllers that you want to support both orientations:
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}