I want only portrait orientation only in one view controller. I am doing this :
-(BOOL)shouldAutorotate{
return NO;
}
-(NSInteger)supportedInterfaceOrientations:(UIWindow *)window{
// UIInterfaceOrientationMaskLandscape;
// 24
//
// UIInterfaceOrientationMaskLandscapeLeft;
// 16
//
// UIInterfaceOrientationMaskLandscapeRight;
// 8
//
// UIInterfaceOrientationMaskPortrait;
// 2
// return UIInterfaceOrientationMaskLandscape;
return 2;
}
No success !!
I have tried many permutations and combinations as suggested on google but still not working.
您应该在shouldAutorotate
返回YES,因为如果您的应用是横向的,在其他情况下您的视图将不会旋转回纵向。
You should try returning YES for shouldAutoRotate to make the below supportedInterfaceOrientations to become effect and also there is no method called -(NSInteger)supportedInterfaceOrientations:(UIWindow *)window on UIViewController instead use:
This code must go in your view controller which you want to be in portrait only.
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
I'm linking you a post where I answered a question like this. I hope it will bel helpful
How to change only one ViewController to landscape mode with UINavigationcontroller
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.