慕课网_《iOS-动画入门》学习总结

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

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

第一章:动画概述

1-1 iOS动画课程概述

iOS动画课程概述

  1. 为什么使用动画
  2. 制作动画的原理
  3. 制作动画的基础
  4. 一些动画特效的实现

第二章:创建动画的灵感

2-1 iOS动画的原理

动画技术较规范的定义是采用逐帧拍摄对象并连续播放而形成运动的影像技术。

2-2 寻找灵感-Dribbble

网址:https://dribbble.com/

2-3 寻找灵感-Capptivate

网址:http://capptivate.co/

2-4 寻找灵感-Google Material Design

网址:http://www.google.com/design/...

第三章:UIView动画详解

3-1 UIView动画概述

相关类图

UIView动画

  1. 位置:Position
  2. 透明度:Opacity
  3. 缩放:Scale
  4. 颜色:Color
  5. 翻转:Rotation

项目整体概览

3-2 Position动画上

代码演示:

  1. //
  2. // PositionViewController.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 PositionViewController: 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. // 动画效果
  31. UIView.animate(withDuration: 2,animations: {
  32. // 从左边移动到右边
  33. self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
  34. // 从顶部移动到底部
  35. self.redSquare.center.y = self.view.bounds.height - self.redSquare.center.y
  36. // 同时从左边到右边和从顶部到底部
  37. self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
  38. self.greenSquare.center.y = self.view.bounds.height - self.greenSquare.center.y
  39. })
  40.  
  41. }
  42. /*
  43. // MARK: - Navigation
  44.  
  45. // In a storyboard-based application,you will often want to do a little preparation before navigation
  46. override func prepare(for segue: UIStoryboardSegue,sender: Any?) {
  47. // Get the new view controller using segue.destinationViewController.
  48. // Pass the selected object to the new view controller.
  49. }
  50. */
  51.  
  52. }

效果如下:

3-3 Position动画下

代码演示:

  1. //
  2. // PositionViewController.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 PositionViewController: 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. // 动画效果
  31. UIView.animate(withDuration: 2,animations: {
  32. // 从左边移动到右边
  33. self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
  34. })
  35. // 动画效果
  36. UIView.animate(withDuration: 1,delay: 0.5,animations: {
  37. super.viewDidAppear(animated)
  38. // 从顶部移动到底部
  39. self.redSquare.center.y = self.view.bounds.height - self.redSquare.center.y
  40. },completion: nil)
  41. // 动画效果
  42. UIView.animate(withDuration: 1,delay: 1,animations: {
  43. super.viewDidAppear(animated)
  44. // 同时从左边到右边和从顶部到底部
  45. self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
  46. self.greenSquare.center.y = self.view.bounds.height - self.greenSquare.center.y
  47. },completion: nil)
  48.  
  49. }
  50. /*
  51. // MARK: - Navigation
  52.  
  53. // In a storyboard-based application,sender: Any?) {
  54. // Get the new view controller using segue.destinationViewController.
  55. // Pass the selected object to the new view controller.
  56. }
  57. */
  58.  
  59. }

效果如下:

3-4 Opacity动画

代码演示:

  1. //
  2. // OpacityViewController.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 OpacityViewController: UIViewController {
  12.  
  13. // 蓝色正方形
  14. @IBOutlet weak var blueSquare: UIView!
  15. override func viewDidLoad() {
  16. super.viewDidLoad()
  17.  
  18. // Do any additional setup after loading the view.
  19. }
  20.  
  21. override func didReceiveMemoryWarning() {
  22. super.didReceiveMemoryWarning()
  23. // Dispose of any resources that can be recreated.
  24. }
  25. override func viewDidAppear(_ animated: Bool) {
  26. super.viewDidAppear(animated)
  27. // 动画效果
  28. UIView.animate(withDuration: 1,animations: {
  29. // 淡化效果
  30. self.blueSquare.alpha = 0.2
  31. })
  32. }
  33. /*
  34. // MARK: - Navigation
  35.  
  36. // In a storyboard-based application,sender: Any?) {
  37. // Get the new view controller using segue.destinationViewController.
  38. // Pass the selected object to the new view controller.
  39. }
  40. */
  41.  
  42. }

效果如下:

3-5 Scale动画

代码演示:

  1. //
  2. // ScaleViewController.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 ScaleViewController: UIViewController {
  12. // 蓝色正方形
  13. @IBOutlet weak var blueSquare: UIView!
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16.  
  17. // Do any additional setup after loading the view.
  18. }
  19.  
  20. override func didReceiveMemoryWarning() {
  21. super.didReceiveMemoryWarning()
  22. // Dispose of any resources that can be recreated.
  23. }
  24. override func viewDidAppear(_ animated: Bool) {
  25. super.viewDidAppear(animated)
  26. UIView.animate(withDuration: 1,animations: {
  27. // 放大2.0倍
  28. self.blueSquare.transform = CGAffineTransform(scaleX: 2.0,y: 2.0)
  29. // 缩小0.3倍
  30. //self.blueSquare.transform = CGAffineTransform(scaleX: 2.0,y: 2.0)
  31. })
  32. }
  33.  
  34. /*
  35. // MARK: - Navigation
  36.  
  37. // In a storyboard-based application,sender: Any?) {
  38. // Get the new view controller using segue.destinationViewController.
  39. // Pass the selected object to the new view controller.
  40. }
  41. */
  42.  
  43. }

效果如下:

3-6 Color动画

代码演示:

  1. //
  2. // ColorViewController.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 ColorViewController: UIViewController {
  12.  
  13. // 蓝色正方形
  14. @IBOutlet weak var blueSquare: UIView!
  15. // label
  16. @IBOutlet weak var name: UILabel!
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19.  
  20. // Do any additional setup after loading the view.
  21. }
  22.  
  23. override func didReceiveMemoryWarning() {
  24. super.didReceiveMemoryWarning()
  25. // Dispose of any resources that can be recreated.
  26. }
  27. override func viewDidAppear(_ animated: Bool) {
  28. super.viewDidAppear(animated)
  29. UIView.animate(withDuration: 1,animations:{
  30. self.blueSquare.backgroundColor = UIColor.red
  31. self.name.textColor = UIColor.white
  32. })
  33. }
  34. /*
  35. // MARK: - Navigation
  36.  
  37. // In a storyboard-based application,sender: Any?) {
  38. // Get the new view controller using segue.destinationViewController.
  39. // Pass the selected object to the new view controller.
  40. }
  41. */
  42.  
  43. }

效果如下:

3-7 Rotation动画

代码演示:

  1. //
  2. // RotationViewController.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 RotationViewController: UIViewController {
  12. // 轮转图
  13. @IBOutlet weak var wheel: UIImageView!
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16.  
  17. // Do any additional setup after loading the view.
  18. }
  19.  
  20. override func didReceiveMemoryWarning() {
  21. super.didReceiveMemoryWarning()
  22. // Dispose of any resources that can be recreated.
  23. }
  24. func spin() {
  25. UIView.animate(withDuration: 1,delay: 0,options: UIViewAnimationOptions.curveLinear,animations: {
  26. // 旋转半圈
  27. //(translationX: self.wheel.transform,y: CGFloat(Double.pi))
  28. self.wheel.transform = self.wheel.transform.rotated(by: CGFloat(Double.pi))
  29. },completion: {(finished) -> Void in
  30. self.spin()
  31. })
  32. }
  33. override func viewDidAppear(_ animated: Bool) {
  34. super.viewDidAppear(animated)
  35. self.spin()
  36. }
  37. /*
  38. // MARK: - Navigation
  39.  
  40. // In a storyboard-based application,sender: Any?) {
  41. // Get the new view controller using segue.destinationViewController.
  42. // Pass the selected object to the new view controller.
  43. }
  44. */
  45.  
  46. }

效果如下:

猜你在找的Swift相关文章