Swift中UIView类方法(animateWithDuration)的使用

需求:利用Swift语言实现OC语言中UIView类方法

[UIView animateWithDuration:0.5 animations:^{

        bgView.alpha= 1;

 }];

在Swift语言相应的方法为:

class func animateWithDuration(duration: NSTimeInterval, animations: (() -> Void)!)  须要传入的參数有两个:1.duration:动画持续的时间(秒计)2.传入一个方法名(闭包,类似于函数指针--》传入的函数的參数为空。返回值为void)


func hideTabBar(){
        //Swift中调用animateWithDuration方法
        self.tabBar.hidden = true
        UIView.animateWithDuration(0.5, animations: alphaDown)
    }

func alphaDown(){
        bgImageView!.alpha = 0
    }

alphaDown函数实现了BgImageView的alpha值渐变的效果。。。欢迎大家批评指正。。。

欢迎大家增加iOS讨论群:爱疯、爱Coding 209476515


原文地址:https://www.cnblogs.com/slgkaifa/p/7285552.html