【发布时间】:2016-09-15 20:35:42
【问题描述】:
我正在寻找一种方法来强制 AVplayer(视频)仅在横向模式下显示(左侧的主页按钮)。这可能吗?
编辑:尝试添加 playerViewController.supportedInterfaceOrientations = .landscapeLeft
收到错误消息 "无法分配给属性:'supportedInterfaceOrientations' 是一个只能获取的属性"
import AVKit
import AVFoundation
UIViewController {
var videoPlayer = AVPlayer()
var playerViewController = AVPlayerViewController()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
play()
}
func play() {
playerViewController.supportedInterfaceOrientations = .landscapeLeft
let moviePath = Bundle.main.path(forResource: "full video", ofType: "mov")
if let path = moviePath {
let url = NSURL.fileURL(withPath: path)
let videoPlayer = AVPlayer(url: url)
let playerViewController = AVPlayerViewController()
playerViewController.player = videoPlayer
self.present(playerViewController, animated: true) {
if let validPlayer = playerViewController.player {
validPlayer.play()
playerViewController.showsPlaybackControls = false
}
}
}
}
}
编辑:尝试添加新的 AVPlayerViewController 子类
import UIKit
import AVFoundation
import AVKit
class LandscapeVideoControllerViewController: AVPlayerViewController {
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .landscapeLeft
}
}
但收到错误消息“方法未覆盖其超类中的任何方法”
【问题讨论】:
标签: ios swift video orientation avplayer