基本动画

来源:互联网 发布:淘宝网店开店 押金 编辑:程序博客网 时间:2024/05/19 16:22

简单的视图出现动画,创建三个UIView,设置相应的出现时间并显示动画效果

        let firstView = UIView(frame:CGRect(x: -200,y: 100,width: 200,height: 50))        firstView.backgroundColor = UIColor.red        self.view.addSubview(firstView)        let secondView = UIView(frame:CGRect(x: -200,y: 200,width: 200,height: 50))        secondView.backgroundColor = UIColor.green        self.view.addSubview(secondView)        let thirdView = UIView(frame:CGRect(x: -200 ,y: 300,width: 200,height: 50))        thirdView.backgroundColor = UIColor.blue        self.view.addSubview(thirdView)

设置动画时间

UIView.animate(withDuration: 1.0, delay: 1.0, options: UIViewAnimationOptions.curveLinear, animations: {() -> Void in                secondView.frame = CGRect(x: 100, y: 200, width: 200, height: 50)            }, completion: {(finish:Bool) -> Void in        })        UIView.animate(withDuration: 1.0, delay: 2.0, options: UIViewAnimationOptions(), animations: {() -> Void in            thirdView.frame = CGRect(x: 100, y: 300, width: 200, height: 50)            }, completion: {(finish:Bool) -> Void in        })

最后附上效果图

原创粉丝点击