piemonte / PBJVision

📸 iOS Media Capture – features touch-to-record video, slow motion, and photography
MIT License
1.94k stars 324 forks source link

Setting the frame for the preview layer results in incorrect frame settings #301

Closed danipralea closed 3 years ago

danipralea commented 8 years ago

Hello and what an awesome work you've done with this library. I would like to thank you for all your hard work.

I integrated it into a Swift project and when I'm trying to set the frame of the preview layer, it results in an inconsistent frame: img_1678

I have this code:

var _previewLayer: AVCaptureVideoPreviewLayer = PBJVision.sharedInstance().previewLayer
@IBOutlet weak var previewView: UIView! // this is the white view in the back

let bounds = self.previewView.layer.bounds
_previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
_previewLayer.bounds = bounds
_previewLayer.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds))
previewView.layer.addSublayer(_previewLayer)
imagine commented 8 years ago

Especially since you're using Swift, you may want to switch to NextLevel