简体   繁体   English

一种View Controller iOS的横向

[英]Landscape orientation for one view controller ios

I want to show one view controller in both orientation in iPhone. 我想在iPhone的两个方向上显示一个视图控制器。 And when the screen is opening the preferred orientation should be portrait only. 当屏幕打开时,首选方向应仅为纵向。 Then according to the device orientation it'll rotate. 然后根据设备方向旋转。 I found some solution and the screen is rotating too. 我找到了解决方法,屏幕也在旋转。 But when I'm entering the screen it is auto rotating to landscape and than I've to manually rotate it to portrait. 但是,当我进入屏幕时,它会自动旋转为横向,然后我必须手动将其旋转为纵向。

Is there a simple solution to this problem? 有解决这个问题的简单方法吗?

You should implement preferredInterfaceOrientationForPresentation and supportedInterfaceOrientations like: 您应该实现PreferredInterfaceOrientationForPresentation和supportedInterfaceOrientations,例如:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
   return UIDeviceOrientationPortrait;
}
//You don't actually need to implement this as UIInterfaceOrientationMaskAllButUpsideDown is the default for iPhone
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskAllButUpsideDown;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM