I have a UIImageView (self.previewImage) in a view that is being used as a preview window for the front facing camera of an iPad. It is square (768x768) and centered in the view. When I grab frames from the camera to save, I end up cropping the full rectangular frame into a square by cutting out a square that is aligned with the TOP of the frame (in portrait mode). No matter what I've tried, the preview window always crops around the CENTER of the frame.
Is there any way to tell the preview to align with the top of the image? If not, is there a way to insert a processing method that can do the crop manually before adding it to the preview?
My original default preview setup was this:
func setupPreviewLayer() {
self.previewLayer = AVCaptureVideoPreviewLayer(session: self.cameraSessionController.session)
self.previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
self.view.layer.addSublayer(previewLayer)
previewLayer?.frame = previewImage.frame
}
I've played with self.previewLayer?.bounds and self.previewLayer?.videoGravity without success.