我一直在使用下面的代码片段来实现只在一半屏幕上呈现视图控制器的效果:
func showPlayerView() {
let controller = storyboard!.instantiateViewController(withIdentifier: "playerViewController") as! PlayerViewController
controller.player = self.player
controller.providesPresentationContextTransitionStyle = true
controller.definesPresentationContext = true
controller.transitioningDelegate = self
self.present(controller, animated: true, completion: nil)
}
extension ViewController : UIViewControllerTransitioningDelegate
{
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
if presented is PlayerViewController {
return HalfSizePresentationController(presentedViewController: presented, presenting: presenting)
}
return nil
}
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return animator
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return animator
}
}
class HalfSizePresentationController : UIPresentationController {
override var frameOfPresentedViewInContainerView: CGRect
{
get {
let height: CGFloat = 200
return CGRect(x: 0, y: UIScreen.main.bounds.height - height, width: UIScreen.main.bounds.width, height: 200)
}
}
}
这曾经在 tvOS 13 上工作,但现在从 tvOS 14 开始,我得到的是:
知道如何在 iOS 14 上实现这一点吗?