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的世 ...
随机推荐
- PLSQL Developer新手使用教程(图文教程)
PLSQL Developer是Oracle数据库开发工具,很牛也很好用,PLSQL Developer功能很强大,可以做为集成调试器,有SQL窗口,命令窗口,对象浏览器和性能优化等功能,下面简单的介 ...
- SharePoint自动化系列——通过PowerShell创建SharePoint Lists
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...
- 由sqlite在手机上的存储位置,引发的onCreate在哪里执行的小结
我们都知道,android为了操作数据库,一般是继承SQLiteOpenHelper类,并实现他的三个函数. 如下所示: package jz.his.db; import android.conte ...
- tomcat架构分析(概览)
出处:http://gearever.iteye.com Tomcat是目前应用比较多的servlet容器.关于tomcat本身的特点及介绍,网上已经有很多描述了,这里不再赘述.Tomcat除了能够支 ...
- Cannot complete request to Marketplace不能打开eclipse marketplace
当打开eclipse marketplace的时候时候,发现有如下错误: --------------------------------------------------------------- ...
- ASP.NET(C#)不提示直接关闭当前页面
protected void Button1_Click(object sender, EventArgs e) { //关闭页面--要弹出提示(IE6及以下不弹出提示) ClientScript.R ...
- rabbitmq系列(一)-基本概念理解
1.简介 RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue protocol)的开源实现.AMQP高级消息队列,说白了就是一个开源的消息中间件.它能解决 ...
- 起来吧!不要做奴隶的ITproject师们!
本文转自林忠信的博客: http://davylin.blog.163.com/blog/static/8138791201441465328380/ 起来吧! 不要做奴隶的ITproject师们! ...
- iOS边练边学--应用数据存储的常用方式(plist,Preference,NSKeyedArchiver)其中的三种
iOS应用数据存储的常用方式: XML属性列表(plist)归档 Preference(偏好设置) NSKeyedArchiver归档(NSCoding) SQLite3--这里暂且不讲 Core D ...
- el 表达式 强制类型转换
el 表达式 强制类型转换 今天有人问我了这个问题 jsp页面中,能否实现 <% request.setAttrites("a","1234"); % ...