我的目标是通过 Core Animation 理解和实现功能。
我认为这并不难,但不幸的是我不知道 swift/Obj C 并且很难理解 native 示例。
可视化实现
那么我到底想做什么(如图所示的几个步骤):
1.
2.
3.
4.
和隐藏 View 的相同步骤(反之亦然,从上到下)直到:
此外,我想让这个 UIView 更通用,我的意思是将这个 UIView 放在我的 StoryBoard 上,并对 AutoLayout 施加约束(以支持不同的设备屏幕) .
有什么想法吗?谢谢!
最佳答案
You can use like this Extension
extension UIView{
func animShow(){
UIView.animate(withDuration: 2, delay: 0, options: [.curveEaseIn],
animations: {
self.center.y -= self.bounds.height
self.layoutIfNeeded()
}, completion: nil)
self.isHidden = false
}
func animHide(){
UIView.animate(withDuration: 2, delay: 0, options: [.curveLinear],
animations: {
self.center.y += self.bounds.height
self.layoutIfNeeded()
}, completion: {(_ completed: Bool) -> Void in
self.isHidden = true
})
}
}
关于ios - UIView appereance 从下到上,反之亦然(核心动画),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42326892/