swift--动画效果
一、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--动画效果的更多相关文章
- Swift - 动画效果的实现方法总结(附样例)
在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimations.这三个方法都是类方法. 一,使用 ...
- iOS开发——动画篇Swift篇&动画效果的实现
Swift - 动画效果的实现 在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimation ...
- Swift - 多个mask的动画效果
Swift - 多个mask的动画效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // TranformFadeView.swi ...
- Swift - 用UIScrollView实现视差动画效果
Swift - 用UIScrollView实现视差动画效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // MoreInfoVi ...
- [Swift通天遁地]五、高级扩展-(11)图像加载Loading动画效果的自定义和缓存
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Swift 带有动画效果的TabBarItem
额...貌似挺长时间没有总结新知识了,最近在看swift,之前swift刚出来的时候大体看了一遍,后来时间长了没看加之swift2.0做了比较大的调整,公司项目也不是用swift写的,也就没怎么看了, ...
- Swift - 使用CABasicAnimation实现动画效果
1,CABasicAnimation类只有三个属性: fromValue:开始值 toValue:结束值 Duration:动画的时间 2,通过animationWithKeyPath键值对的方式设置 ...
- swift中实现cell中局部播放的动画效果
在cell中 // 播放器动画效果 private var replicatorLayer:ReplicatorLayer = { let layer = ReplicatorLayer.init(f ...
- swift 动画合集
本例参照objective-c的动画合集进行swift的转换,objective-c地址参照地址https://github.com/yixiangboy/IOSAnimationDemo 1.基础动 ...
- Swift动画编程指南-01 简介
大家好,我是老镇,这段时间家里和工作上发生了很多的事情,所以很长一段时间都没有出来搞什么小动作了.在接下来的一段时间内我会制作一些列关于使用Swift进行动画编程的视频,希望和大家胃口. 在iOS的世 ...
随机推荐
- JNDI到底是什么,有什么作用
http://shitou521.iteye.com/blog/696006 ******************************************* JNDI的一篇文章 前端时间总是在 ...
- js JSON对象与字符串相互转换
从服务器接收到数据一般是字符串的形式.如果是JSON格式的字符串,就需要先将其转换成JSON对象.JSON对象在浏览器输出为objcet,我们看不到具体的数据.所以将JSON对象转换成字符串. 下面将 ...
- dp之混合背包poj1742(推荐)
题意:给你价值为a1,a2.....的货币,每种有c1,c2.......个,求这些货币所能组成的价值小于等于m有多少个..... 思路:很像一道多重背包题?那我一开始的确是用多重背包的思路编写的.. ...
- hdu4366 Successor
好题. 可是感觉题目描写叙述不是非常清楚 这题仅仅是询问开除某人后,他的下属中谁会替代他的位置.不会更新这个位置 要求一个子树中忠诚度最高的人. 能够想到dfs树.保留时间戳.每一个节点便表示一个 ...
- 配置TOMCAT 修改默认ROOT路径
本文转载http://xxs673076773.iteye.com/blog/1134805 最合适的) 最直接的办法是,删掉tomcat下原有Root文件夹,将自己的项目更名为Root. 我在$to ...
- jsp页面积累
out.print(页面html);response.setContexttype("");以页面的形式展现java
- 传说中的纯CSS圆角代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- 数据库 Oracle监听实例详解
Oracle实例别名 IMCDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = )) (CONNECT_D ...
- MapReduce生成HFile入库到HBase
转自:http://www.cnblogs.com/shitouer/archive/2013/02/20/hbase-hfile-bulk-load.html 一.这种方式有很多的优点: 1. 如果 ...
- selenium测试(Java)-- 验证信息(八)
package com.test.validationinfor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.f ...