简体   繁体   English

View Controller并显示另一个View Controller

[英]View Controller and displaying another View Controller

I want this. 我要这个。 vc1(performSegue to vc3) -> vc2(For 2 seconds)-dismiss -> vc3 vc1(执行到vc3的执行)-> vc2(持续2秒钟)-关闭-> vc3

I refer to this. 我指的是这个。 https://stackoverflow.com/a/39824680/11094223 https://stackoverflow.com/a/39824680/11094223

VC1 CameraViewController 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 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 vc3 PreviewViewController

If you do this When moving from vc2 to vc3, vc1 comes out for a while, then goes to vc3. 如果执行此操作从vc2移至vc3时,vc1会出现一段时间,然后转到vc3。 I want to go straight from vc2 to vc3.(dismiss). 我想直接从vc2转到vc3。(关闭)。 not good at English. 英文不好。 I'm sorry 对不起

The issue that you are having is because you are animating the dismissal of vc2. 您遇到的问题是因为您正在为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. showVC3的动画将像在vc2上一样播放。 vc2 meanwhile will disappear from the stack. vc2同时将从堆栈中消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM