最新消息:20190529 VPS服务器已从腾讯云香港换为Vultr新加坡,主题仍用朋友推荐的大前端D8

[已解决]ios设置是否支持横屏和竖屏

iOS crifan 1297浏览 0评论

swift的app

默认好像是支持横屏的

但是当iPhone屏幕有旋转的话,就会变成对应的横屏,

此处不想要横屏,要去禁止横屏,只支持默认的竖屏。

可以看到,默认设置的支持的模式:

iPhone有三种

iPad有4种

swift 禁止竖屏

swift 禁止横屏

swift 禁止app横屏的方式 – 简书

搜:

supportedInterfaceOrientations

UIViewController Class Reference

Handling View Rotations

As of iOS 8, all rotation-related methods are deprecated. Instead, rotations are treated as a change in the size of the view controller’s view and are therefore reported using the viewWillTransitionToSize:withTransitionCoordinator: method. When the interface orientation changes, UIKit calls this method on the window’s root view controller. That view controller then notifies its child view controllers, propagating the message throughout the view controller hierarchy.

In iOS 6 and iOS 7, your app supports the interface orientations defined in your app’s Info.plist file. A view controller can override the supportedInterfaceOrientations method to limit the list of supported orientations. Typically, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen; child view controllers use the portion of the window provided for them by their parent view controller and no longer participate directly in decisions about what rotations are supported. The intersection of the app’s orientation mask and the view controller’s orientation mask is used to determine which orientations a view controller can be rotated into.

You can override the preferredInterfaceOrientationForPresentation for a view controller that is intended to be presented full screen in a specific orientation.

When a rotation occurs for a visible view controller, the willRotateToInterfaceOrientation:duration:willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation:methods are called during the rotation. The viewWillLayoutSubviews method is also called after the view is resized and positioned by its parent. If a view controller is not visible when an orientation change occurs, then the rotation methods are never called. However, the viewWillLayoutSubviews method is called when the view becomes visible. Your implementation of this method can call the statusBarOrientation method to determine the device orientation.

NOTE

At launch time, apps should always set up their interface in a portrait orientation. After the application:didFinishLaunchingWithOptions: method returns, the app uses the view controller rotation mechanism described above to rotate the views to the appropriate orientation prior to showing the window.

ios8 screen rotate

ios8 screen orientation

objective c – iOS 9 supportedInterfaceOrientations not working – Stack Overflow

先去info.plist中改为:

再去项目设置中看看

果然也是只支持竖屏,其他的不支持了:

然后去试试效果,看看是否还会屏幕旋转时变横屏

再去iPhone真机试试旋转效果

就可以了:

旋转屏幕后,始终都保持(Home键在下面的)Portrait模式

另外,也看到,实际上Info.plist中是xml的key,去掉了其他几个模式:

转载请注明:在路上 » [已解决]ios设置是否支持横屏和竖屏

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
61 queries in 0.098 seconds, using 18.82MB memory