View Controller并显示另一个View Controller

时间:2019-03-13 11:39:38

标签: ios swift uiviewcontroller

我想要这个。 vc1(执行到vc3的执行)-> vc2(持续2秒钟)-关闭-> vc3

我指的是这个。 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

如果您这样做 从vc2移到vc3时,vc1会出现一段时间,然后转到vc3。 我想直接从vc2转到vc3。(关闭)。 英文不好。对不起

1 个答案:

答案 0 :(得分:0)

您遇到的问题是因为您正在为vc2的动画设置动画。只需将其更改为:

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

showVC3的动画将像在vc2上一样播放。 vc2同时将从堆栈中消失。