ios - Camera Preview Not Fitting To UIView -
i'm making camera , i've decided make sort of square instagram camera , iphone default camera. i'm encountering problem image doesn't fit uiview. below example of happening. uiview should covering red edges left , right.
here code starts session...
func reloadcamera() { cameraview.backgroundcolor = uicolor.clearcolor() capturesession = avcapturesession() capturesession!.sessionpreset = avcapturesessionpresethigh let backcamera = avcapturedevice.defaultdevicewithmediatype(avmediatypevideo) if (camera == false) { let videodevices = avcapturedevice.deviceswithmediatype(avmediatypevideo) device in videodevices { let device = device as! avcapturedevice if device.position == avcapturedeviceposition.front { capturedevice = device break } else { capturedevice = backcamera } } } else { capturedevice = avcapturedevice.defaultdevicewithmediatype(avmediatypevideo) } { let input = try avcapturedeviceinput(device: capturedevice) if capturesession!.canaddinput(input) { capturesession!.addinput(input) stillimageoutput = avcapturestillimageoutput() stillimageoutput!.outputsettings = [avvideocodeckey: avvideocodecjpeg] if capturesession!.canaddoutput(stillimageoutput) { capturesession!.addoutput(stillimageoutput) previewlayer = avcapturevideopreviewlayer(session: capturesession) previewlayer!.videogravity = avlayervideogravityresizeaspect previewlayer!.connection?.videoorientation = avcapturevideoorientation.portrait cameraview.layer.addsublayer(previewlayer!) previewlayer?.frame = cameraview.bounds capturesession!.startrunning() } } } catch let error nserror { // handle errors print(error) } }
there no constraint issues whatsoever , i've tried deleting elements , having code above run didn't work. tell me if need more information. thanks! (:
Comments
Post a Comment