Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Rounded Corners on Camera View

I want to implement rounded corners on my RecordingViewController(which has the camera view).I tried going into the app delegate and changing the corner radius of the window however, it seemed to not work. I believe the issue is with this method (AVLayerVideoGravityResizeAspectFill), it seems to fill the entire screen and takes no consideration to changing the window corner radius. Any ideas?

like image 627
OriginalAlchemist Avatar asked Nov 25 '25 11:11

OriginalAlchemist


1 Answers

  var captureSession:AVCaptureSession?   
  var videoPreviewLayer:AVCaptureVideoPreviewLayer?

First of all create a UIView and give it corner radius. After that add AVCaptureVideoPreviewLayer as sublayer to that view.

    myView.layer.masksToBounds = true

    videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
    videoPreviewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
    videoPreviewLayer?.frame = myView.layer.bounds
    myView.layer.addSublayer(videoPreviewLayer!)

Hope this helps.

like image 111
Developer Avatar answered Nov 26 '25 23:11

Developer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!