ios - 同时 UIViewController 过渡动画
问题描述
我正在尝试淡入背景渐变图像并将uiview
卡片从底部(屏幕外)向上滑动到中心- 当模态呈现uiviewcontroller
时同时执行两个动画。uiviewcontroller
我尝试将uiviewcontroller
模态过渡样式设置为交叉溶解,这将为背景渐变图像提供淡入效果,并在运行动画时将卡片从底部viewDidAppear
向上滑动到中心。uiview
虽然这可行,但卡有一点延迟,理想情况下我希望两个动画同时发生。
这种分组可以吗?任何指导将不胜感激。
以下是模态呈现的视图控制器中的相关代码:
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)
}
解决方案
这个工作就像一个魔术。我喜欢它。
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)
}
}
推荐阅读
- node.js - 带有mobilenet和blazeface的Tensorflow js服务器端分类
- amazon-web-services - 为应用用户快速高效地播放音频和视频的最常用方法?
- vue.js - 您正在运行 Vue 的 esm-bundler 构建。建议配置您的捆绑器
- javascript - 在 Javascript 计算器中链接多个运算符
- python-3.x - 位置参数元组的替换索引 1 超出范围
- api - Magento 2 REST API 理解领域
- xcode - 如何使用 yml 运行 Xcode 测试?
- php - 当元素计数相同时,PHP combine_array 产生 false
- php - 在 PHP 中同时执行多个语句/行
- python - 如何告诉用户使用 Tweepy、Python 进行了验证