简体   繁体   English

查看卡在肖像中迅速

[英]View stuck in portrait in swift

I have a view in a view controller. 我在视图控制器中有一个视图。

When I rotate the device, the view controller rotates, but the view seems to be stuck in portrait mode. 当我旋转设备时,视图控制器也会旋转,但是视图似乎卡在纵向模式下。

Check the image from the simulator. 检查模拟器中的图像。

来自模拟器

You should rearrange the view for the landscape. 您应该重新排列景观的视图。

You can do this by code, changing the elements position when detect a rotation , or, the more usual way, using auto-layout , here you have a more detailed guide to how to do it. 您可以通过代码, 在检测到旋转时更改元素位置来执行此操作,或者更常见的方法是使用自动布局在此处,您将获得有关操作方法的更详细的指南。

Another way of solving, is not enabling rotation, you can set in the General options of the project, like this a portrait only mode. 解决的另一种方法是不启用旋转,可以在项目的“常规”选项中进行设置,例如纵向模式。

在此处输入图片说明

If you'd like the view to be independent from the orientation change, and resize itself, I would suggest looking into Xcode's Auto-Layout . 如果您希望视图独立于方向变化并自行调整大小,建议您使用Xcode的Auto-Layout

If you'd like to disallow orientation changes for your entire application (your view will rotate with the phone), see @UlyssesR 's answer. 如果您想禁止整个应用程序的方向更改(您的视图将随手机一起旋转),请参见@UlyssesR的答案。

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

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