如何在Swift 1.2中从底部到顶部动画UIlabel

Vig*_*h J 0 animation uiviewanimation ios swift

打开视图控制器时,我想从下到上为标签设置动画.

我可以在没有框架或pod文件的情况下为标签设置动画吗?

Zac*_*ler 8

没有必要使用框架或pod来实现您想要完成的任务.您只需使用以下方法并调整持续时间和距离即可满足您的需求.

    UIView.animate(withDuration: 2, delay: 0, options: [.curveEaseOut], 
    animations: {
        label.center.y -= self.view.bounds.height - 100
        self.view.layoutIfNeeded()
    }, completion: nil)
Run Code Online (Sandbox Code Playgroud)

那里有"-100",因此您不会完全将视图中的标签设置为动画.如果您的标签开始接近顶部,则需要增加此数字,反之亦然