0

I want this. vc1(performSegue to vc3) -> vc2(For 2 seconds)-dismiss -> vc3

I refer to this. https://stackoverflow.com/a/39824680/11094223

VC1 CameraViewController

func showVC3() {

    performSegue(withIdentifier: "showPhoto_Segue", sender: nil)
}

@IBAction func cameraButton_TouchUpInside(_ sender: Any) {

    let settings = AVCapturePhotoSettings()
    photoOutput?.capturePhoto(with: settings, delegate: self)

}
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showLoading_Segue" {
        let loadVC = segue.destination as! showLoadingViewController

        loadVC.delegate = self


    }else if segue.identifier == "showPhoto_Segue" {
        let previewVC = segue.destination as! PreviewViewController
        previewVC.frameSet = frameSet
        previewVC.frameImage = frameImage
        previewVC.image = self.image
    }
}

extension CameraViewController: AVCapturePhotoCaptureDelegate {
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
    if let imageData = photo.fileDataRepresentation() {
        image = UIImage(data: imageData)

        performSegue(withIdentifier: "showLoading_Segue", sender: nil)

    }
}

}

vc2 showLoadingViewController

protocol VC2Delegate {
func showVC3()
}



var delegate: VC2Delegate?
override func viewDidLoad() {
    super.viewDidLoad()

    let time = DispatchTime.now() + .seconds(2)
    DispatchQueue.main.asyncAfter(deadline: time) {
        self.showPreview()
    }
}

func showPreview(){

    dismiss(animated: true, completion: nil)
    if let _ = delegate {
        delegate?.showVC3()
    }
}

vc3 PreviewViewController

If you do this When moving from vc2 to vc3, vc1 comes out for a while, then goes to vc3. I want to go straight from vc2 to vc3.(dismiss). not good at English. I'm sorry

1 Answers1

0

The issue that you are having is because you are animating the dismissal of vc2. Just change it to:

    dismiss(animated: false, completion: nil)
    if let _ = delegate {
        delegate?.showVC3()
    }

The animation for showVC3 will play as if it was showing over vc2. vc2 meanwhile will disappear from the stack.

Josh Homann
  • 15,933
  • 3
  • 30
  • 33