ios – 有没有办法在swift中将相机设置为横向模式?

ios – 有没有办法在swift中将相机设置为横向模式?,第1张

概述如何将相机设置为横向模式?每次拍照时,图像都会保存为肖像图像.当设备处于横向模式时,照片看起来很好但是如果我在相机胶卷中看到它仍然是纵向模式. 这是我的拍照功能: // take a photo@IBAction func takePhoto(sender: AnyObject) { self.fullScreenView.hidden = false self.recordBu 如何将相机设置为横向模式?每次拍照时,图像都会保存为肖像图像.当设备处于横向模式时,照片看起来很好但是如果我在相机胶卷中看到它仍然是纵向模式.
这是我的拍照功能:

// 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中将相机设置为横向模式?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1030730.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存