问题
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;
}
来源:https://stackoverflow.com/questions/37085341/how-to-set-certain-view-controller-to-be-landscape-and-portrait-and-certain-to-b