【问题标题】:Simultaneous UIViewController Transition Animations同时 UIViewController 过渡动画
【发布时间】:2018-11-06 00:15:56
【问题描述】:

我正在尝试淡入背景渐变图像并将uiview 卡片从底部(屏幕外)滑到uiviewcontroller 的中心 - 当uiviewcontroller 出现时同时执行两个动画模态的。

我尝试将uiviewcontroller 模态过渡样式设置为交叉溶解,这将为背景渐变图像提供淡入效果,并在viewDidAppear 中运行动画以向上滑动@987654326 @card 从底部到中心。

虽然这可行,但卡有一点延迟,理想情况下我希望两个动画同时发生。

可以这样分组吗?任何指导将不胜感激。

以下是模态呈现的视图控制器中的相关代码:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    alertViewCenterYConstraint.constant += view.bounds.height

}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    UIView.animate(withDuration: 0.1, delay: 0, options: .curveEaseOut, animations: {
        self.alertViewCenterYConstraint.constant = 0
        self.view.layoutIfNeeded()
    }, completion: nil)
}

【问题讨论】:

    标签: ios swift uiviewanimation presentmodalviewcontroller


    【解决方案1】:

    这个工作就像一个魔术。我喜欢它。

       override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        alertViewCenterYConstraint.constant += view.bounds.height
        DispatchQueue.main.async {
        UIView.animate(withDuration: 0.1, delay: 0.05, options: .curveEaseOut, animations: {
            self.alertViewCenterYConstraint.constant = 0
            self.view.layoutIfNeeded()
        }, completion: nil)
    
        }
    }
    

    【讨论】:

    • 完美运行!是因为在主线程上运行动画吗?只是好奇。
    • 是的。你说的对。如果不在主线程上,它会阻塞布局。如果你尝试,你可以看到它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 2014-02-27
    • 2016-02-26
    • 2016-11-01
    • 1970-01-01
    相关资源
    最近更新 更多