iOS系统中的应用大多都灵活运用了各种各样的动画来让自己的应用变的丰富多彩,一个App对动画的运用直接影响了用户体验,学习iOS动画编程是非常有用的
UIView中提供了最基础的动画这里来演示一下
首先实现控件从左侧飞入界面控件我之前已经做好了连线,在viewWillAppear方法中将它们移除视图
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) heading.center.x -= view.bounds.width username.center.x -= view.bounds.width password.center.x -= view.bounds.width }
override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) //参数为动画的运行时间 UIView.animateWithDuration(0.5) { () -> Void in self.heading.center.x += self.view.bounds.width } //参数为动画的运行时间、延时、动画选项、完成后的动作 //通过延时实现几个控件不同时间飞入 UIView.animateWithDuration(0.5, delay: 0.3, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in self.username.center.x += self.view.bounds.width }, completion: nil) UIView.animateWithDuration(0.5, delay: 0.6, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in self.password.center.x += self.view.bounds.width }, completion: nil) }