资讯专栏INFORMATION COLUMN

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

aervon / 2368人阅读

摘要:时间年月日星期一说明本文部分内容均来自慕课网。慕课网教学示例源码个人学习源码第一章动画进阶学习课程前,请先学习慕课网动画入门学习总结。

时间: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 Repeat

UIView动画的重复执行:Repeat

代码演示:

//
//  RepeatViewController.swift
//  iOSAnimationDemo
//
//  Created by zc on 2017/5/22.
//  Copyright © 2017年 com.zccoder. All rights reserved.
//

import UIKit

class RepeatViewController: UIViewController {
    
    // 蓝色方块
    @IBOutlet weak var blueSquare: UIView!
    // 红色方块
    @IBOutlet weak var redSquare: UIView!
    // 绿色方块
    @IBOutlet weak var greenSquare: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        UIView.animate(withDuration: 1, animations: {
            // 蓝色方块从左边移动到右边
            self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
        })
        
        UIView.animateKeyframes(withDuration: 1, delay: 0, options: .repeat, animations: {
            // 红色方块重复执行从左边移动到右边
            self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
        }, completion: nil)
        
        UIView.animateKeyframes(withDuration: 1, delay: 0, options: [.repeat, .autoreverse], animations: {
            // 绿色方块重复执行从左边移动到右边然后从右边移动到左边
            self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
        }, completion: nil)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

效果如下:

1-3 Easing上

UIView Easing动画

1-4 Easing下

代码演示:

//
//  EasingViewController.swift
//  iOSAnimationDemo
//
//  Created by zc on 2017/5/22.
//  Copyright © 2017年 com.zccoder. All rights reserved.
//

import UIKit

class EasingViewController: UIViewController {
    
    @IBOutlet weak var blueSquare: UIView!
    @IBOutlet weak var redSquare: UIView!
    @IBOutlet weak var greenSquare: UIView!
    @IBOutlet weak var yellowSquare: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        UIView.animate(withDuration: 1, animations: {
            // 蓝色方块从左边移动到右边-均速移动
            self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
        })
        
        UIView.animate(withDuration: 1, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations: {
            // 红色方块从左边移动到右边-先慢后快
            self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
        }, completion: nil)
        
        UIView.animate(withDuration: 1, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
            // 绿色方块从左边移动到右边-先快后慢
            self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
        }, completion: nil)
        
        UIView.animate(withDuration: 1, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
            // 黄色方块从左边移动到右边-两边快中间慢
            self.yellowSquare.center.x = self.view.bounds.width - self.yellowSquare.center.x
        }, completion: nil)
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

效果如下:

1-5 Spring上

UIView Spring动画:Spring:类似弹簧

1-6 Spring下

代码演示:

//
//  SpringViewController.swift
//  iOSAnimationDemo
//
//  Created by zc on 2017/5/22.
//  Copyright © 2017年 com.zccoder. All rights reserved.
//

import UIKit

class SpringViewController: UIViewController {

    @IBOutlet weak var blueSquare: UIView!
    @IBOutlet weak var redSquare: UIView!
    @IBOutlet weak var greenSquare: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        // 蓝色方块从左边移动到右边-均速移动
        UIView.animate(withDuration: 1, animations: {
            self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
        })
        
        // 红色方块从左边移动到右边-弹簧效果
        UIView.animate(withDuration: 5, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0, options: [], animations: {
            self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
        }, completion: nil)
        
        // 绿色方块从左边移动到右边-先快后慢
        UIView.animate(withDuration: 5, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 1, options: [], animations: {
            self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
        }, completion: nil)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

效果如下:

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/16762.html

相关文章

  • 课网_iOS-动画入门》学习总结

    时间:2017年05月15日星期一说明:本文部分内容均来自慕课网。@慕课网:http://www.imooc.com教学示例源码:https://github.com/zccodere/s...个人学习源码:https://github.com/zccodere/s... 第一章:动画概述 1-1 iOS动画课程概述 iOS动画课程概述 为什么使用动画 制作动画的原理 制作动画的基础 一些动画特效...

    widuu 评论0 收藏0
  • 课网_《SpringBoot进阶之Web进阶学习总结

    摘要:时间年月日星期日说明本文部分内容均来自慕课网。慕课网教学示例源码个人学习源码第一章课程介绍课程介绍本课程紧接着小时学会课程,请先看入门课。异常返回通知在连接点抛出异常后执行。 时间:2017年3月19日星期日说明:本文部分内容均来自慕课网。@慕课网:http://www.imooc.com教学示例源码:https://github.com/zccodere/s...个人学习源码:htt...

    lifefriend_007 评论0 收藏0
  • 课网_《一起来做价值百万的Apple Watch App:分歧终端机》学习总结

    摘要:时间年月日星期一说明本文部分内容均来自慕课网。慕课网教学示例源码个人学习源码第一章课程简介下载课程简介制作一个猜拳游戏,剪刀石头布。 时间:2017年05月22日星期一说明:本文部分内容均来自慕课网。@慕课网:http://www.imooc.com教学示例源码:https://github.com/zccodere/s...个人学习源码:https://github.com/zcco...

    oysun 评论0 收藏0
  • 课网_iOS基础教程-文件操作》学习总结

    摘要:时间年月日星期二说明本文部分内容均来自慕课网。文件路径写入图片慕课网图片 时间:2017年06月06日星期二说明:本文部分内容均来自慕课网。@慕课网:http://www.imooc.com教学示例源码:无个人学习源码:https://github.com/zccodere/s... 第一章:学习指南 1-1 学习指南 应用需求 showImg(https://segmentfault...

    cartoon 评论0 收藏0
  • 课网_iOS基础入门之Foundation框架初体验》学习总结

    时间:2017年05月10日星期三说明:本文部分内容均来自慕课网。@慕课网:http://www.imooc.com教学示例源码:无个人学习源码:https://github.com/zccodere/s... 第一章:Foundation结构简介 1-1 Foundation结构关系 Foundation.framework Foundation:基础 framework:框架 基础框架 Fou...

    desdik 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<