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的世 ...
随机推荐
- jar包调用jar包内部和外部的配置文件
http://blog.csdn.net/lpftobetheone/article/details/32689467 **************************************** ...
- LeetCode: Gray Code 解题报告
Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit ...
- LeetCode: Substring with Concatenation of All Words 解题报告
Substring with Concatenation of All Words You are given a string, S, and a list of words, L, that ar ...
- .Net应该学什么怎么学(一)
更新时间:2012年06月05日18时21分 来源:传智播客.Net 上篇<学了.Net做什么开发>中我讲到了目前.Net开发主要方向是Web开发,因此在本篇中我将主要讲解做Web开发要学 ...
- 利用IT++搭建通信仿真平台
IT++ is a C++ library of mathematical, signal processing and communication classes and functions.也就是 ...
- C语言高速入门系列(八)
C语言高速入门系列(八) C语言位运算与文件 本章引言: 在不知不觉中我们的C高速入门系列已经慢慢地接近尾声了,而在这一节中,我们会对 C语言中的位运算和文件进行解析,相信这两章对于一些人来说是陌生的 ...
- 測试Service
<strong><span style="font-size:18px;">自己定义Service:</span></strong> ...
- Unix 系统下的 Nginx 1.4.x
Unix 系统下的 Nginx 1.4.x 本文档包括使用 PHP-FPM 为 Nginx 1.4.x HTTP 服务器安装和配置 PHP 的说明和提示. 本指南假定您已经从源代码成功构建 Nginx ...
- 跑在Docker下的RHEL7编译Java8源码包
1.运行Docker时需要加参数--cap-add=SYS_PTRACE,比如: docker run --cap-add=SYS_PTRACE --name buildjava8 -v /opt/r ...
- 获取pc硬件信息杂记
//Download by http://www.NewXing.com #include "StdAfx.h" #include "RegUtil.h" #i ...