简体   繁体   English

如何在 Swift 1.2 中从下到上动画 UIlabel

[英]How to animate UIlabel from bottom to top in Swift 1.2

I want to animate the label from bottom to top when opening a view controller.我想在打开视图控制器时从下到上为标签设置动画。

Can I Animated the label Without frameworks or pod file?我可以在没有框架或 pod 文件的情况下为标签设置动画吗?

There's no need to use frameworks or pods for what you are trying to accomplish.无需使用框架或 pod 来完成您要完成的任务。 You can simply use the following method and tweak the duration and distance to fit your needs.您可以简单地使用以下方法并调整持续时间和距离以满足您的需要。

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

The "-100" is there so that you don't animate the label out of the view completely. “-100”在那里,因此您不会完全将标签设置为视图之外。 If your label starts closer to the top you will need to increase this number and vice versa如果您的标签开始靠近顶部,则需要增加此数字,反之亦然

Here transition example with Swift 1.2, from another question .这里是 Swift 1.2 的转换示例,来自另一个问题

Swift 3, 4, 5斯威夫特 3、4、5

UIView.transition(with: status, duration: 0.33, options:
    [.curveEaseOut, .transitionCurlDown], animations: {
        //...animations
}, completion: {_ in
    //....transition completion
    delay(seconds: 2.0) {

    }
})

Swift 2.0斯威夫特 2.0

UIView.transitionWithView(status, duration: 0.33, options:
        [.CurveEaseOut, .TransitionCurlDown], animations: {
            //...animations
     }, completion: {_ in
            //....transition completion
            delay(seconds: 2.0) {

     }
})

Swift 1.2斯威夫特 1.2

UIView.transitionWithView(status, duration: 0.33, options:
        .CurveEaseOut | .TransitionCurlDown, animations: {
            //...animations
     }, completion: {_ in
            //transition completion
            delay(seconds: 2.0) {

     }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM