i'm working on video player app that written in Swift
.
my problem is i should make AVPlayerViewController
corners curve. but i want to use just AVPlayerViewController
not any other classes.
what i did now:
fileprivate func setupPlayer() {
let player = AVPlayer(url: videoURL)
let playerViewController = AVPlayerViewController()
playerViewController.view.frame = CGRect.init(x: xPosition,
y: yPosition,
width: 200,
height: 100)
playerViewController.player = player
self.addChild(playerViewController)
self.view.addSubview(playerViewController.view)
playerViewController.didMove(toParent: self)
playerViewController.videoGravity = AVLayerVideoGravity.init(rawValue: "")
playerViewController.view.backgroundColor = UIColor(displayP3Red: 0/255, green: 0/255, blue: 0/255, alpha: 0)
playerViewController.view.layer.cornerRadius = 20
playerViewController.contentOverlayView?.isHidden = true
playerViewController.contentOverlayView?.alpha = 0
}
what i already have is:
but i want to have something curve like the one in appstore:
The AVPlayerViewController
adds a sub layer to your view. When you set the playerViewController.view.layer.cornerRadius
property it only affects it and not its children.
To fix it you must clip the subviews (or here the sublayer) by using the masksToBounds
layer property.
playerViewController.view.layer.masksToBounds = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With