2016-09-19 1 views
0

신속한 2에서이 코드를 사용했는데 효과가있었습니다. 그러나 이제 Swift 3에서는 녹음이 끝나면 팝업되는 미리보기 컨트롤러 창이 취소 또는 저장 버튼을 누르면 사라지지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?왜 Swift에서 리플레이 키트 previewController를 닫지 않습니까?

previewController.dismiss(animated: true, completion: nil) 

에 :

func stopRecording() { 

let sharedRecorder = RPScreenRecorder.shared() 
sharedRecorder.stopRecording(handler: { (previewController: RPPreviewViewController?, error) in 

if previewController != nil { 
      print("stopped recording") 

       self.previewViewController.previewControllerDelegate = self 
       self.view?.window?.rootViewController?.present(previewController!, animated: true, completion: nil) 
} 



func previewControllerDidFinish(previewController: RPPreviewViewController) { 

previewController.dismiss(animated: true, completion: nil) 

} 

답변

1

//이 코드를 사용해보십시오 희망이 도움이 :

func startRecording() { 
    let recorder = RPScreenRecorder.shared() 

    if #available(iOS 9.0, *) { 
     recorder.startRecording(withMicrophoneEnabled: true) { [unowned self] (error) in 
      if let unwrappedError = error { 
       print(unwrappedError.localizedDescription) 
      } else { 
       self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Stop", style: .plain, target: self, action: #selector(PreviewVC.stopRecording)) 
      } 
     } 
    } else { 
     // Fallback on earlier versions 
    } 
} 

func stopRecording() { 
    let recorder = RPScreenRecorder.shared() 

    recorder.stopRecording { [unowned self] (preview, error) in 
     self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Start", style: .plain, target: self, action: #selector(PreviewVC.startRecording)) 

     if let unwrappedPreview = preview { 
      unwrappedPreview.previewControllerDelegate = self 
      self.present(unwrappedPreview, animated: true, completion: nil) 
     } 
    } 
} 

func previewControllerDidFinish(_ previewController: RPPreviewViewController) { 
    self.dismiss(animated: true, completion: nil) 
} 
1

당신은에서 마지막 줄을 변경해야합니다

dismiss(animated: true, completion: nil)