学Swift挣美金

Swift 教程之TableView使用06 动画效果

2019-05-06  本文已影响3人  iCloudEnd

Swift 教程之TableView使用06 动画效果

效果图

Jietu20190506-105949.gif

之前系列课程

1.添加两个存储高度的变量

    fileprivate var imageHeightColsed: NSLayoutConstraint!
    fileprivate var imageHeightOpened: NSLayoutConstraint!

2. 配置动画函数

  func animate(){
        self.imageHeightOpened.isActive = false
        self.imageHeightColsed.isActive = true
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
            self.imageHeightColsed.isActive = false
            self.imageHeightOpened.isActive = true
            
            UIView.animate(
                withDuration: 0.3,
                delay:0.15,
                usingSpringWithDamping: 0.2,
                initialSpringVelocity: 0.1,
                options: .curveEaseIn,
                animations: {
                    self.contentView.layoutIfNeeded()
                    
            },completion: nil)
        }
    }

动画的原理非常简单,您给出开始和结束状态,剩下的复杂工作就交给runtime去做吧。

上一篇 下一篇

猜你喜欢

热点阅读