首页 > 解决方案 > 自定义segue完成后相机关闭?

问题描述

我正在尝试使用自定义过渡到全屏自定义相机。当我使用慢速淡入淡出动画这样做时,完成动画后它会变黑。

动画开始时似乎工作的相机突然消失了,留下了黑色背景。

如何使过渡正常工作?

代码:

主VC:

@objc func buttonUp(_ sender: UIButton) {

    toCam.transform = CGAffineTransform.identity.scaledBy(x: 1, y: 1)
    toCam.backgroundColor = .yellow

    segue()
}

func segue() {
    performSegue(withIdentifier: "GoToCam", sender: self)
}

自定义 segue 类:

class goToCamAnimCustom: UIStoryboardSegue {

    override func perform() {
        scale()
    }

    func scale() {

        guard let destinationView = self.destination.view else {
            // Fallback to no fading
            self.source.present(self.destination, animated: false, completion: nil)
            return
        }

        destinationView.alpha = 0
        self.source.view?.addSubview(destinationView)

        UIView.animate(withDuration: CATransaction.animationDuration(), animations: {
            destinationView.alpha = 0.5
        }, completion: { _ in
            self.source.present(self.destination, animated: false, completion: nil)
        })

    }
}

标签: iosswiftseguetransition

解决方案


推荐阅读