这是我的拍照功能:
// take a photo@IBAction func takePhoto(sender: AnyObject) { self.fullScreenVIEw.hIDden = false self.recordbutton.enabled = false self.takephoto.enabled = false self.recordbutton.hIDden = true self.takephoto.hIDden = true session.startRunning() // customize the quality level or bitrate of the output photo session.sessionPreset = AVCaptureSessionPresetPhoto // add the AVCaptureVIDeoPrevIEwLayer to the vIEw and set the vIEw in fullscreen fullScreenVIEw.frame = vIEw.bounds vIDeoPrevIEwLayer.frame = fullScreenVIEw.bounds fullScreenVIEw.layer.addSublayer(vIDeoPrevIEwLayer) // add action to fullScreenVIEw gestureFullScreenVIEw = UITapGestureRecognizer(target: self,action: #selector(VIEwController.takePhoto(_:))) self.fullScreenVIEw.addGestureRecognizer(gestureFullScreenVIEw) // add action to myVIEw gestureVIEw = UITapGestureRecognizer(target: self,action: #selector(VIEwController.setFrontpage(_:))) self.vIEw.addGestureRecognizer(gestureVIEw) if (prevIEw == true) { if let vIDeoConnection = stillimageOutput!.connectionWithMediaType(AVMediaTypeVIDeo) { // code for photo capture goes here... stillimageOutput?.captureStillimageAsynchronouslyFromConnection(vIDeoConnection,completionHandler: { (sampleBuffer,error) -> VoID in // process the image data (sampleBuffer) here to get an image file we can put in our vIEw if (sampleBuffer != nil) { let imageData = AVCaptureStillimageOutput.jpegStillimageNSDataRepresentation(sampleBuffer) let image = UIImage(data: imageData,scale: 1.0) self.fullScreenVIEw.hIDden = true self.fullScreenVIEw.gestureRecognizers?.forEach(self.fullScreenVIEw.removeGestureRecognizer) self.session.stopRunning() // save image to the library UIImageWritetoSavedPhotosAlbum(image!,nil,nil) self.imageVIEwBackground = UIImageVIEw(frame: self.vIEw.bounds) self.imageVIEwBackground.image = image self.imageVIEwBackground.tag = self.key self.vIEw.addSubvIEw(self.imageVIEwBackground) } }) } } else { prevIEw = true }}
提前致谢!
EDIT
我的预览看起来像那样,那没关系:
http://img5.fotos-hochladen.net/uploads/bildschirmfotom4s7diaehy.png
但最终看起来像这样:
http://img5.fotos-hochladen.net/uploads/bildschirmfoto3c2rlwtevf.png
解决方法 我使用这个函数,这可能对你有用:overrIDe func vIEwWillTransitionToSize(size: CGSize,withTransitionCoordinator coordinator: UIVIEwControllerTransitionCoordinator) { super.vIEwWillTransitionToSize(size,withTransitionCoordinator: coordinator) let orIEntation = UIDevice.currentDevice().orIEntation if UIDeviceOrIEntationIsPortrait(orIEntation) || UIDeviceOrIEntationIsLandscape(orIEntation) { if let vIDeoOrIEntation = AVCaptureVIDeoOrIEntation(rawValue: orIEntation.rawValue) { (captureVIEw.layer as! AVCaptureVIDeoPrevIEwLayer).connection.vIDeoOrIEntation = vIDeoOrIEntation } } }总结
以上是内存溢出为你收集整理的ios – 有没有办法在swift中将相机设置为横向模式?全部内容,希望文章能够帮你解决ios – 有没有办法在swift中将相机设置为横向模式?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)