gpt4 book ai didi

ios - 水平呈现 avplayer

转载 作者:行者123 更新时间:2023-11-30 13:50:31 24 4
gpt4 key购买 nike

有没有办法在应用程序中仅允许一个 View Controller 使用横向模式?我以如下方式呈现它:

let recViewController = AVPlayerViewController()
recViewController.modalTransitionStyle = .CoverVertical
recViewController.player = AVPlayer(URL: NSURL(string: currentScores[selectedButtonIndexPath.row].recapAvailable))
recViewController.player.play()

self.view.window?.rootViewController?.presentViewController(recViewController, animated: true, completion: nil)

我知道我可以手动覆盖每个 View Controller 以仅允许垂直方向(上面的除外),但这看起来相当乏味。

最佳答案

有什么办法可以在应用程序中只允许一个 View Controller 使用横向模式吗?

您自己已经回答了问题,请参阅“Configuring the View Rotation Settings” ' 在 UIViewController 类引用中。您需要配置您的应用程序以支持您想要的所有旋转,然后覆盖每个 View Controller ,是的,这很乏味,但它有效:)

Handling View RotationsAs of iOS 8, all rotation-related methods aredeprecated. Instead, rotations are treated as a change in the size ofthe view controller’s view and are therefore reported using theviewWillTransitionToSize:withTransitionCoordinator: method. When theinterface orientation changes, UIKit calls this method on the window’sroot view controller. That view controller then notifies its childview controllers, propagating the message throughout the viewcontroller hierarchy.

In iOS 6 and iOS 7, your app supports the interface orientationsdefined in your app’s Info.plist file. A view controller can overridethe supportedInterfaceOrientations method to limit the list ofsupported orientations. Typically, the system calls this method onlyon the root view controller of the window or a view controllerpresented to fill the entire screen; child view controllers use theportion of the window provided for them by their parent viewcontroller and no longer participate directly in decisions about whatrotations are supported. The intersection of the app's orientationmask and the view controller's orientation mask is used to determinewhich orientations a view controller can be rotated into.

You can override the preferredInterfaceOrientationForPresentation fora view controller that is intended to be presented full screen in aspecific orientation.

When a rotation occurs for a visible view controller, thewillRotateToInterfaceOrientation:duration:,willAnimateRotationToInterfaceOrientation:duration:, anddidRotateFromInterfaceOrientation: methods are called during therotation. The viewWillLayoutSubviews method is also called after theview is resized and positioned by its parent. If a view controller isnot visible when an orientation change occurs, then the rotationmethods are never called. However, the viewWillLayoutSubviews methodis called when the view becomes visible. Your implementation of thismethod can call the statusBarOrientation method to determine thedevice orientation.

<小时/>

编辑

您还可以查看UIApplicationDelegate Protocol ,它有方法

func application(application: UIApplication,
supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask

来自文档:

Discussion

This method returns the total set of interface orientationssupported by the app. When determining whether to rotate a particularview controller, the orientations returned by this method areintersected with the orientations supported by the root viewcontroller or topmost presented view controller. The app and viewcontroller must agree before the rotation is allowed.

If you do not implement this method, the app uses the values in theUIInterfaceOrientation key of the app’s Info.plist as the defaultinterface orientations.

<小时/>

关于ios - 水平呈现 avplayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34346840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com