慕课网_《iOS-动画进阶》学习总结

前端之家收集整理的这篇文章主要介绍了慕课网_《iOS-动画进阶》学习总结前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

时间:2017年05月22日星期一
说明:本文部分内容均来自慕课网。@慕课网:http://www.imooc.com
教学示例源码:https://github.com/zccodere/s...
个人学习源码:https://github.com/zccodere/s...

第一章:动画进阶

1-1 Timing

学习课程前,请先学习慕课网_《iOS-动画入门》学习总结。

UIView动画的Timing

  1. 属性的原始状态
  2. 属性的结束状态
  3. 执行时长
  4. 执行过程
  5. 执行完毕的处理

1-2 Repeat

UIView动画的重复执行:Repeat

代码演示:

  1. //
  2. // RepeatViewController.swift
  3. // iOSAnimationDemo
  4. //
  5. // Created by zc on 2017/5/22.
  6. // Copyright © 2017年 com.zccoder. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class RepeatViewController: UIViewController {
  12. // 蓝色方块
  13. @IBOutlet weak var blueSquare: UIView!
  14. // 红色方块
  15. @IBOutlet weak var redSquare: UIView!
  16. // 绿色方块
  17. @IBOutlet weak var greenSquare: UIView!
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20.  
  21. // Do any additional setup after loading the view.
  22. }
  23.  
  24. override func didReceiveMemoryWarning() {
  25. super.didReceiveMemoryWarning()
  26. // Dispose of any resources that can be recreated.
  27. }
  28. override func viewDidAppear(_ animated: Bool) {
  29. super.viewDidAppear(animated)
  30. UIView.animate(withDuration: 1,animations: {
  31. // 蓝色方块从左边移动到右边
  32. self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
  33. })
  34. UIView.animateKeyframes(withDuration: 1,delay: 0,options: .repeat,animations: {
  35. // 红色方块重复执行从左边移动到右边
  36. self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
  37. },completion: nil)
  38. UIView.animateKeyframes(withDuration: 1,options: [.repeat,.autoreverse],animations: {
  39. // 绿色方块重复执行从左边移动到右边然后从右边移动到左边
  40. self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
  41. },completion: nil)
  42. }
  43.  
  44. /*
  45. // MARK: - Navigation
  46.  
  47. // In a storyboard-based application,you will often want to do a little preparation before navigation
  48. override func prepare(for segue: UIStoryboardSegue,sender: Any?) {
  49. // Get the new view controller using segue.destinationViewController.
  50. // Pass the selected object to the new view controller.
  51. }
  52. */
  53.  
  54. }

效果如下:

1-3 Easing上

UIView Easing动画

1-4 Easing下

代码演示:

  1. //
  2. // EasingViewController.swift
  3. // iOSAnimationDemo
  4. //
  5. // Created by zc on 2017/5/22.
  6. // Copyright © 2017年 com.zccoder. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class EasingViewController: UIViewController {
  12. @IBOutlet weak var blueSquare: UIView!
  13. @IBOutlet weak var redSquare: UIView!
  14. @IBOutlet weak var greenSquare: UIView!
  15. @IBOutlet weak var yellowSquare: UIView!
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18.  
  19. // Do any additional setup after loading the view.
  20. }
  21.  
  22. override func didReceiveMemoryWarning() {
  23. super.didReceiveMemoryWarning()
  24. // Dispose of any resources that can be recreated.
  25. }
  26. override func viewDidAppear(_ animated: Bool) {
  27. super.viewDidAppear(animated)
  28. UIView.animate(withDuration: 1,animations: {
  29. // 蓝色方块从左边移动到右边-均速移动
  30. self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
  31. })
  32. UIView.animate(withDuration: 1,options: UIViewAnimationOptions.curveEaseIn,animations: {
  33. // 红色方块从左边移动到右边-先慢后快
  34. self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
  35. },completion: nil)
  36. UIView.animate(withDuration: 1,options: UIViewAnimationOptions.curveEaSEOut,animations: {
  37. // 绿色方块从左边移动到右边-先快后慢
  38. self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
  39. },options: UIViewAnimationOptions.curveEaseInOut,animations: {
  40. // 黄色方块从左边移动到右边-两边快中间慢
  41. self.yellowSquare.center.x = self.view.bounds.width - self.yellowSquare.center.x
  42. },completion: nil)
  43. }
  44.  
  45.  
  46. /*
  47. // MARK: - Navigation
  48.  
  49. // In a storyboard-based application,sender: Any?) {
  50. // Get the new view controller using segue.destinationViewController.
  51. // Pass the selected object to the new view controller.
  52. }
  53. */
  54.  
  55. }

效果如下:

1-5 Spring上

UIView Spring动画:Spring:类似弹簧

1-6 Spring下

代码演示:

  1. //
  2. // SpringViewController.swift
  3. // iOSAnimationDemo
  4. //
  5. // Created by zc on 2017/5/22.
  6. // Copyright © 2017年 com.zccoder. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class SpringViewController: UIViewController {
  12.  
  13. @IBOutlet weak var blueSquare: UIView!
  14. @IBOutlet weak var redSquare: UIView!
  15. @IBOutlet weak var greenSquare: UIView!
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18.  
  19. // Do any additional setup after loading the view.
  20. }
  21.  
  22. override func didReceiveMemoryWarning() {
  23. super.didReceiveMemoryWarning()
  24. // Dispose of any resources that can be recreated.
  25. }
  26. override func viewDidAppear(_ animated: Bool) {
  27. super.viewDidAppear(animated)
  28. // 蓝色方块从左边移动到右边-均速移动
  29. UIView.animate(withDuration: 1,animations: {
  30. self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
  31. })
  32. // 红色方块从左边移动到右边-弹簧效果
  33. UIView.animate(withDuration: 5,usingSpringWithDamping: 0.3,initialSpringVelocity: 0,options: [],animations: {
  34. self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
  35. },completion: nil)
  36. // 绿色方块从左边移动到右边-先快后慢
  37. UIView.animate(withDuration: 5,initialSpringVelocity: 1,animations: {
  38. self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
  39. },sender: Any?) {
  40. // Get the new view controller using segue.destinationViewController.
  41. // Pass the selected object to the new view controller.
  42. }
  43. */
  44.  
  45. }

效果如下:

猜你在找的Swift相关文章