2017-08-01 7 views
0

私はAVFoundationで作業しており、フルスクリーンカメラビューを作成しています。私は、fpsを変更してステータスバーを隠すことができないようです。私はfpsを140 fps(iPhone 7用)に設定したいと思いますし、ステータスバーも隠しておきたいです(私のストーリーボードファイルとXcodeアプリ設定のGeneralタブで変更しました)。私のViewControllerの事前のおかげでこれを達成(私はスウィフト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)ステータスバーを非表示にするには、 UIViewControllerprefersStatusBarHidden:メソッドのオーバーライドを追加:定数FPSを設定するには

override var prefersStatusBarHidden : Bool { 
    return true 
} 

2)あなたは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))") 
    } 
} 
関連する問題