Swift 在iphone和ipad中调整视频框的大小

Swift 在iphone和ipad中调整视频框的大小,swift,xcode,Swift,Xcode,我想为iPhone和iPad创建一个应用程序,我的应用程序包含的视频不是全屏的,我把视频放在一个有代码的框架中 private func playVideo(){ guard let path=Bundle.main.path(forResource:“ch”,类型为“mp4”)else{ debugPrint(“找不到video.mp4”) 返回 } let player=AVPlayer(url:url(fileURLWithPath:path)) 让playerController=AVP

我想为iPhone和iPad创建一个应用程序,我的应用程序包含的视频不是全屏的,我把视频放在一个有代码的框架中

private func playVideo(){
guard let path=Bundle.main.path(forResource:“ch”,类型为“mp4”)else{
debugPrint(“找不到video.mp4”)
返回
}
let player=AVPlayer(url:url(fileURLWithPath:path))
让playerController=AVPlayerViewController()
playerController.player=玩家
let controller=avplayervewcontroller()
controller.player=player
controller.view.frame=CGRect(x:1,y:40,宽度:self.view.bounds.width-2,高度:280)
self.view.addSubview(controller.view)
self.addChild(控制器)
player.play()
}
我将其设置为280,这对iPhone设备很有好处

但我想在iPad设备上设置550帧的高度,但没人能帮我,谢谢


您应该根据设备高度设置计算出的高度

大概

controller.view.frame = CGRect(x: 1, y: 40, width: self.view.bounds.width - 2, 
                              height: UIScreen.main.bounds.size.height * 0.66)

Okan Kocyigit它工作正常,感谢您的回答,感谢您的编辑,Ahmet Sina Ustem