我正在播放的视频不占用UIView
(名为videoView)的整个区域,该区域为灰色:iPhone 7 Plus Simulator Screenshot
大多数答案声称我需要将框架设置为边界(UIView
)或将videoGravity
设置为AVLayerVideoGravityResizeAspectFill
。我已经尝试了两种方法,但由于某种原因,它仍然没有完全填满这个空间。
var avPlayer: AVPlayer!
var avPlayerLayer: AVPlayerLayer!
var paused: Bool = false
@IBOutlet weak var videoView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let theURL = Bundle.main.url(forResource:"HOTDOG", withExtension: "mp4")
avPlayer = AVPlayer(url: theURL!)
avPlayerLayer = AVPlayerLayer(player: avPlayer)
avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
avPlayerLayer.frame = videoView.layer.bounds
videoView.layer.insertSublayer(avPlayerLayer, at: 0)
}
任何帮助将不胜感激。 :)
答案 0 :(得分:2)
经过很长一段时间我找到了答案。
下面的代码应该移到viewDidAppear()中,如:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Resizing the frame
avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
avPlayerLayer.frame = videoView.layer.bounds
videoView.layer.insertSublayer(avPlayerLayer, at: 0)
avPlayer.play()
paused = false
}
布局是为iPhone SE(小屏幕)设计的,所以当它在更大的屏幕上测试时,应用程序从自动布局中取出原始设置的大小并根据它进行整形。通过将代码移动到viewDidAppear()中,应用程序根据新约束调整窗口大小。
答案 1 :(得分:0)
只需将框架线#==== connect to postgreSQL ======#
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:postgresql://localhost:5432/rs_ecommerce
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
# Disable feature detection by this undocumented parameter. Check the org.hibernate.engine.jdbc.internal.JdbcServiceImpl.configure method for more details.
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
# Because detection is disabled you have to set correct dialect by hand.
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
# seems like we don't need to put the below driver properties in application.properties file for latest version of postgreSQL.
spring.datasource.driver-class-name=org.postgresql.Driver
移到avPlayerLayer.frame = videoView.layer.bounds
中,就像这样:
viewDidLayoutSubviews
其余部分应该像您一样坚持使用override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
avPlayerLayer.frame = videoView.layer.bounds
}
函数。