'Swift AVPlayerLayer videoGravity .resizeAspect only respects height not width
I have an AVPlayer and AVPlayerLayer embedded in a simple UIView. This plays the movie but adjusting playerLayer.videoGravity only effects the movies relative height:
.resizeAspectfills all the way to side of thevideoviewUIView and crops the height.resizeAspectFilllooks like a zoomed in version of the stretched.resizeAspect
var player = AVPlayer()
@IBOutlet weak var videoview: UIView!
override func viewDidAppear(_ animated: Bool) {
player = AVPlayer(url: url)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.setAffineTransform(CGAffineTransform(rotationAngle: CGFloat((-90 * Double.pi)/180)))
playerLayer.frame = videoview.bounds
playerLayer.videoGravity = .resizeAspect
videoview.layer.addSublayer(playerLayer)
player.play()
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
