2017-08-01 71 views
0

我正在使用AVFoundation並製作全屏相機視圖。我似乎無法改變fps並隱藏狀態欄。我希望將fps設置爲140 fps(對於iPhone 7),我還希望隱藏狀態欄(我在故事板文件和Xcode應用程序設置的「常規」選項卡中更改了它。我提前實現這一謝謝(我用的雨燕3.0,寧願在斯威夫特3(如果可能)的答案)如何使用AVFoundation和相機視圖更改fps和隱藏狀態欄

視圖控制器的代碼:?!`類的ViewController:UIViewController的{

@IBOutlet var cameraView: UIImageView! 
let captureSession = AVCaptureSession() 
let stillImageOutput = AVCaptureStillImageOutput() 
var previewLayer : AVCaptureVideoPreviewLayer? 

var captureDevice : AVCaptureDevice? 

func beginSession() { 

    do { 
     try captureSession.addInput(AVCaptureDeviceInput(device: captureDevice)) 
     stillImageOutput.outputSettings = [AVVideoCodecKey:AVVideoCodecJPEG] 

     if captureSession.canAddOutput(stillImageOutput) { 
      captureSession.addOutput(stillImageOutput) 
     } 

    } 
    catch { 
     print("error: \(error.localizedDescription)") 
    } 

    guard let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) else { 
     print("no preview layer") 
     return 
    } 

    self.view.layer.addSublayer(previewLayer) 
    previewLayer.frame = self.view.layer.frame 
    captureSession.startRunning() 
} 

override func viewWillAppear(_ animated: Bool) { 
    super.viewWillAppear(animated) 

    captureSession.sessionPreset = AVCaptureSessionPresetHigh 

    if let devices = AVCaptureDevice.devices() as? [AVCaptureDevice] { 
     // Loop through all the capture devices on this phone 
     for device in devices { 
      // Make sure this particular device supports video 
      if (device.hasMediaType(AVMediaTypeVideo)) { 
       // Finally check the position and confirm we've got the back camera 
       if(device.position == AVCaptureDevicePosition.back) { 
        captureDevice = device 
        if captureDevice != nil { 
         print("Capture device found") 
         beginSession() 
        } 
       } 
      } 
     } 
    } 


} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

}

`

回答

0

1)要隱藏狀態欄,您應該添加prefersStatusBarHidden:方法的UIViewController的控制裝置:

override var prefersStatusBarHidden : Bool { 
    return true 
} 

2)設定的常數FPS可以使用AVCaptureDevice實例的activeVideoMinFrameDurationactiveVideoMaxFrameDuration屬性:

func setFrameRate(_ captureDevice: AVCaptureDevice) { 
    do { 
     try captureDevice.lockForConfiguration() 
     captureDevice.activeVideoMinFrameDuration = CMTimeMake(1, 140) 
     captureDevice.activeVideoMaxFrameDuration = CMTimeMake(1, 140) 
     captureDevice.unlockForConfiguration() 
    } catch { 
     NSLog("An Error occurred: \(error.localizedDescription))") 
    } 
}