ios - 使用所需的动画和方向为特定视图设置动画
问题描述
我正在尝试通过将约束设置为 0 或 100 来设置视图的动画以显示和显示。我遇到的问题是如何更改动画样式或方向?因为视图将从下到上进行动画处理,但我想从上到下显示视图。
我不能使用self.view.layoutIfneeded
,因为我不希望它为整个视图设置动画。我只想以正确的方向为特定视图设置动画。谢谢。
UIView.animate(withDuration: 0.5, delay: 0, options: .allowUserInteraction, animations: {
//self.view.layoutIfNeeded()
self.topButtonView.layoutIfNeeded()
}, completion: nil)
解决方案
利用CGAffineTransform
// move the view to top 100 offset from current y
self.topButtonView.transform = CGAffineTransform.identity.translatedBy(x: 0, y: -100)
// then reset the transform
// it will animate downward (back to it's original position)
UIView.animate(withDuration: 0.5, delay: 0, options: .allowUserInteraction, animations: {
self.topButtonView.transform = .identity
}, completion: nil)
推荐阅读
- ubuntu - Electron Builder-Ubuntu 中的 DMG
- nginx - 如何让 NGINX 重新解析 DNS?
- sql - 如果达到阈值,SQL SUM 停止
- vue.js - 在 vuetify 中找不到相关模块
- firebase - Firebase:相同的用户名
- matlab - 在 Manjaro 上安装 Matlab
- spring - GitLab CI CD runner 未加载配置文件的属性文件
- javascript - Jest Mock 返回未定义而不是数据
- git - 除非 Windows 服务用户拥有 Devops 帐户,否则 Jenkins 管道配置页面无法访问 GIT
- r - GGPlot 2色点按分类数据