一、for循环创建4*4个view,然后对立面的所有view进行动画,这里列集中动画的效果:

1,旋转动画

        for tile in backgrounds{

            //现将数字块大小职位原始尺寸的1/10
tile.layer.setAffineTransform(CGAffineTransform(scaleX: 0.1,y: 0.1)) //设置动画效果,动画时间长度1秒
UIView.animate(withDuration: , delay: 0.01, options: [], animations: { }, completion: { (finished) in UIView.animate(withDuration: , animations: {
//完成动画时,数字块复原
tile.layer.setAffineTransform(CGAffineTransform.identity)
}) }) }

2,不透明到透明的效果

        for tile in backgrounds {

            tile.alpha = 

            //设置动画效果,动画时间长度1秒
UIView.animate(withDuration: , delay: 0.01, options: [.curveEaseInOut], animations: { }, completion: { (finished) in
UIView.animate(withDuration: , animations: {
tile.alpha =
})
}) }

3,从小到大的效果

        for tile in backgrounds {

            //现将数字快大小之前原始尺寸的1/10
tile.layer.setAffineTransform(CGAffineTransform(scaleX:0.1,y:0.1)) //设置动画效果,动画时间长度1秒
UIView.animate(withDuration: , delay: 0.01, options: [], animations: {
tile.layer.setAffineTransform(CGAffineTransform(scaleX:,y:))
}, completion: { (finished) in
UIView.animate(withDuration: 0.08, animations: {
tile.layer.setAffineTransform(CGAffineTransform.identity)
})
}) }

记录下三种动画效果

二、使用beginAnimations和commitAnimations方法来实现动画

beginAnimations:此方法开始一个动画快,调用commitAnimations结束一个动画块,并且动画块是允许嵌套的。

commitAnimations:此方法用于结束一个动画块,动画时在一个独立的线程中运行的,动画在生效时,所用应用程序不会中断。

beginAnimations和commitAnimations中间的代码中,我们可以设置各种动画的属性,比如持续时间,使用哪算阈值的动画效果等。

1)淡入、淡出、移动、改变大小动画

func animationAction() {
//淡出动画
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(2.0)
imgV.alpha = 0.0
UIView.commitAnimations() //淡入动画
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(2.0)
imgV.alpha = 1.0
UIView.commitAnimations() //移动动画
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(2.0)
imgV.center = CGPoint(x:,y:)
UIView.commitAnimations() //大小调整动画
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(2.0)
imgV.frame = CGRect(x:,y:,width:,height:)
UIView.commitAnimations()
}

UIViewAnimationTransition定义了 5 种过渡动画类型:

  • none:无过渡动画效果
  • flipFromLeft:从左侧向右侧翻转
  • flipFromRight:从右侧向左侧翻转
  • curlUp:向上卷数翻页
  • curlDown:向下翻页

代码如下:

 //翻页动画 一 向左翻页
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(2.5)
UIView.setAnimationTransition(.curlUp, for: self.view1!, cache: true)
self.view.exchangeSubview(at: , withSubviewAt: )
UIView.commitAnimations() //翻页动画 二 旋转
UIView.beginAnimations("animation", context: nil)
UIView.setAnimationDuration(2.0)
UIView.setAnimationCurve(.easeInOut)
UIView.setAnimationTransition(.flipFromLeft, for: self.view2!, cache: false)
self.view.exchangeSubview(at: , withSubviewAt: )
UIView.commitAnimations()

跳转到其他页面的操作:

 let EleventhVC = EleventhViewController()
let windows = UIApplication.shared.delegate?.window
let nav = UINavigationController(rootViewController:EleventhVC) UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(2.0)
UIView.setAnimationCurve(.easeInOut)
UIView.setAnimationTransition(.curlUp, for: windows!!, cache: true)
UIView.commitAnimations()
windows??.rootViewController = nav

主界面做动画:

UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(2.0)
UIView.setAnimationCurve(.easeOut)
UIView.setAnimationTransition(.curlDown, for: self.view, cache: false)
UIView.commitAnimations()

swift--动画效果的更多相关文章

  1. Swift - 动画效果的实现方法总结(附样例)

    在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimations.这三个方法都是类方法. 一,使用 ...

  2. iOS开发——动画篇Swift篇&动画效果的实现

    Swift - 动画效果的实现   在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimation ...

  3. Swift - 多个mask的动画效果

    Swift - 多个mask的动画效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // TranformFadeView.swi ...

  4. Swift - 用UIScrollView实现视差动画效果

    Swift - 用UIScrollView实现视差动画效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // MoreInfoVi ...

  5. [Swift通天遁地]五、高级扩展-(11)图像加载Loading动画效果的自定义和缓存

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. Swift 带有动画效果的TabBarItem

    额...貌似挺长时间没有总结新知识了,最近在看swift,之前swift刚出来的时候大体看了一遍,后来时间长了没看加之swift2.0做了比较大的调整,公司项目也不是用swift写的,也就没怎么看了, ...

  7. Swift - 使用CABasicAnimation实现动画效果

    1,CABasicAnimation类只有三个属性: fromValue:开始值 toValue:结束值 Duration:动画的时间 2,通过animationWithKeyPath键值对的方式设置 ...

  8. swift中实现cell中局部播放的动画效果

    在cell中 // 播放器动画效果 private var replicatorLayer:ReplicatorLayer = { let layer = ReplicatorLayer.init(f ...

  9. swift 动画合集

    本例参照objective-c的动画合集进行swift的转换,objective-c地址参照地址https://github.com/yixiangboy/IOSAnimationDemo 1.基础动 ...

  10. Swift动画编程指南-01 简介

    大家好,我是老镇,这段时间家里和工作上发生了很多的事情,所以很长一段时间都没有出来搞什么小动作了.在接下来的一段时间内我会制作一些列关于使用Swift进行动画编程的视频,希望和大家胃口. 在iOS的世 ...

随机推荐

  1. vs2010静态链接Qt

    先按照这个帖子弄好静态库 http://www.cnblogs.com/rollenholt/articles/2518642.html 注意原文中config那一步最后一个"-" ...

  2. C#深入总结

    面向对象编程好处:提高软件可复用性.可扩展性.易维护性.灵活性第一章:理解.NET Framework与C# 1..NET框架由.NET Frmaework和CLR组成: 2.CLR(公共语言运行时) ...

  3. 多重连接的数据库管理工具:Navicat Premium

    多重连接的数据库管理工具:Navicat Premium 2016-09-26 Navicat Premium(非免费软件)是一个可多重连接的数据库管理工具,它可让你以单一程序同时连接到MySQL.O ...

  4. LeetCode: Spiral Matrix 解题报告

    Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix ...

  5. linux oracle 查看版本

    1.查找 which sqlplus /u01/app/oracle/product/10.2.0/db_1/bin/sqlplus 可以带出 oracle 安装地址  2.登录 sqlplus 输入 ...

  6. 关于HTML、XHTML、CSS、XML的区别

    1.HTML(Hyper Text Mark-up Language) HTML(Hyper Text Mark-up Language)即超文本标记语言或超文本链接标示语言,是为“网页创建和其他可在 ...

  7. dvwa 源码分析(二) --- dvwaPage.inc.php分析

    在setup.php中,包含了这个文件,所以这里分析这个文件. <?php if( !defined( 'DVWA_WEB_PAGE_TO_ROOT' ) ) { define( 'DVWA S ...

  8. flume sourcetype avro http

    flume  当sourcetype=http的时候可以用 curl -X POST -d '[{"headers" :{"APPSTORE" : " ...

  9. Android——事件处理模型一(基于回调机制的事件处理)(转)

    Android平台的事件处理机制有两种,一种是基于回调机制的,一种是基于监听接口的,现介绍第一种:基于回调机制的事件处理.Android平台中,每个View都有自己的处理事件的回调方法,开发人员可以通 ...

  10. Lua语言开发Cocos2d-x游戏视频教程第L0401课-Cocos2d-x中使用Lua

    http://www.eoeandroid.com/thread-320733-1-1.html