swift - swift - 从左侧为 SlideIn 和 SlideOut 设置动画
问题描述
如何快速从左侧滑入和滑出菜单?下面的代码显示了左侧的菜单,但是当 slideIn 快速发生并且它实际上并没有显示菜单来自左侧。此外,slideOut 从右侧而不是左侧关闭菜单。
这是我的代码:
UIView.animate(withDuration: 0.5, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
self.blackView.alpha = 1
self.collectionView.frame = CGRect(x: 0, y: 0, width:
self.collectionView.frame.width - 10, height:
self.collectionView.frame.height)
}, completion: nil)
也适用于幻灯片
UIView.animate(withDuration: 0.5, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.blackView.alpha = 0
if let window = UIApplication.shared.keyWindow {
self.collectionView.frame = CGRect(x: window.frame.width, y: 0, width: self.collectionView.frame.width, height: self.collectionView.frame.height)
}
}) { (completed: Bool)
任何建议表示赞赏。
解决方案
//Slide in
self.collectionView.frame = CGRect(x: -(window.frame.width), y: 0, width: window.frame.width-50, height: window.frame.height)
UIView.animate(withDuration: 0.5, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
self.blackView.alpha = 1
self.collectionView.frame = CGRect(x: 0, y: 0, width: window.frame.width-50, height: window.frame.height)
}, completion: nil)
//Slide out
UIView.animate(withDuration: 0.5, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.blackView.alpha = 0
if let window = UIApplication.shared.keyWindow {
self.collectionView.frame = CGRect(x: -(window.frame.width), y: 0, width: window.frame.width-50, height: window.frame.height)
}
}, completion: nil)
推荐阅读
- javascript - 带有选项输入字段的下拉列表
- c++ - 如何使这个小写和大写
- typescript - 如何在 TypeScript Compiler - tsc 中排除引用的 Firebase 模块?
- python - 使用 Py2app 时出现导入错误
- python-3.x - 使用 Bazel 构建 TensorFlow:执行 genrule //tensorflow:tensorflow_python_api_gen failed (Exit 1): bash failed: error execution command
- html - 如何将图像和标签放在彼此的顶部 HTML CSS
- database - 有人可以从公钥中获取私钥吗?
- mysql - 如何使用不存在而不是内连接?
- java - 使用源代码的最新更改运行 .bat 文件
- swift - 我想把 func internetChanged 放在另一个文件中。(关于可达性)