用 Swift 制作一个漂亮的汉堡按钮过渡动画

- let shortStroke: CGPath = {
- let path = CGPathCreateMutable()
- CGPathMoveToPoint(path, nil, 2, 2)
- CGPathAddLineToPoint(path, nil, 28, 2)
- return path
- }()

- let outline: CGPath = {
- let path = CGPathCreateMutable()
- CGPathMoveToPoint(path, nil, 10, 27)
- CGPathAddCurveToPoint(path, nil, 12.00, 27.00, 28.02, 27.00, 40, 27)
- CGPathAddCurveToPoint(path, nil, 55.92, 27.00, 50.47, 2.00, 27, 2)
- CGPathAddCurveToPoint(path, nil, 13.16, 2.00, 2.00, 13.16, 2, 27)
- CGPathAddCurveToPoint(path, nil, 2.00, 40.84, 13.16, 52.00, 27, 52)
- CGPathAddCurveToPoint(path, nil, 40.84, 52.00, 52.00, 40.84, 52, 27)
- CGPathAddCurveToPoint(path, nil, 52.00, 13.16, 42.39, 2.00, 27, 2)
- CGPathAddCurveToPoint(path, nil, 13.16, 2.00, 2.00, 13.16, 2, 27)
- return path
- }()
- self.top.path = shortStroke
- self.middle.path = outline
- self.bottom.path = shortStroke
- layer.fillColor = nil
- layer.strokeColor = UIColor.whiteColor().CGColor
- layer.lineWidth = 4
- layer.miterLimit = 4
- layer.lineCap = kCALineCapRound
- layer.masksToBounds = true
- let boundingPath = CGPathCreateCopyByStrokingPath(layer.path, nil, 4, kCGLineCapRound, kCGLineJoinMiter, 4)
- layer.bounds = CGPathGetPathBoundingBox(boundingPath)
- self.top.anchorPoint = CGPointMake(28.0 / 30.0, 0.5)
- self.top.position = CGPointMake(40, 18)
- self.middle.position = CGPointMake(27, 27)
- self.middle.strokeStart = hamburgerStrokeStart
- self.middle.strokeEnd = hamburgerStrokeEnd
- self.bottom.anchorPoint = CGPointMake(28.0 / 30.0, 0.5)
- self.bottom.position = CGPointMake(40, 36)
- var transform = CATransform3DIdentity
- transform = CATransform3DTranslate(transform, -4, 0, 0)
- transform = CATransform3DRotate(transform, -M_PI_4, 0, 0, 1)
- let animation = CABasicAnimation(keyPath: "transform")
- animation.fromValue = NSValue(CATransform3D: CATransform3DIdentity)
- animation.toValue = NSValue(CATransform3D: transform)
- animation.timingFunction = CAMediaTimingFunction(controlPoints: 0.25, -0.8, 0.75, 1.85)
- animation.beginTime = CACurrentMediaTime() + 0.25
- self.top.addAnimation(animation, forKey: "transform")
- self.top.transform = transform
- let menuStrokeStart: CGFloat = 0.325
- let menuStrokeEnd: CGFloat = 0.9
- let hamburgerStrokeStart: CGFloat = 0.028
- let hamburgerStrokeEnd: CGFloat = 0.111
- let strokeStart = CABasicAnimation(keyPath: "strokeStart")
- strokeStart.fromValue = hamburgerStrokeStart
- strokeStart.toValue = menuStrokeStart
- strokeStart.duration = 0.5
- strokeStart.timingFunction = CAMediaTimingFunction(controlPoints: 0.25, -0.4, 0.5, 1)
- self.middle.addAnimation(strokeStart, forKey: "strokeStart")
- self.middle.strokeStart = menuStrokeStart
- let strokeEnd = CABasicAnimation(keyPath: "strokeEnd")
- strokeEnd.fromValue = hamburgerStrokeEnd
- strokeEnd.toValue = menuStrokeEnd
- strokeEnd.duration = 0.6
- strokeEnd.timingFunction = CAMediaTimingFunction(controlPoints: 0.25, -0.4, 0.5, 1)
- self.middle.addAnimation(strokeEnd, forKey: "strokeEnd")
- self.middle.strokeEnd = menuStrokeEnd

用 Swift 制作一个漂亮的汉堡按钮过渡动画的更多相关文章
- Swift 制作一个新闻通知中心插件1
使用 Swift 制作一个新闻通知中心插件(1) 随着 iOS 8 的发布,苹果为开发者们开放了很多新的 API,而在这些开放的接口中 通知中心插件 无疑是最显眼的一个.通知中心就不用过多介绍了,相信 ...
- 小强的HTML5移动开发之路(5)——制作一个漂亮的视频播放器
来自:http://blog.csdn.net/dawanganban/article/details/17679069 在前面几篇文章中介绍了HTML5的特点和需要掌握的基础知识,下面我们开始真正的 ...
- 纯Div+Css制作的漂亮点击按钮和关闭按钮
纯Div+Css制作的漂亮点击按钮和关闭按钮,单击点击按钮也有效果.这些都不是图片.
- 使用 Swift 制作一个新闻通知中心插件(1)
input[type="date"].form-control,.input-group-sm>input[type="date"].input-grou ...
- Swift - 制作一个在线流媒体音乐播放器(使用StreamingKit库)
在之前的文章中,我介绍了如何使用 AVPlayer 制作一个简单的音乐播放器(点击查看1.点击查看2).虽然这个播放器也可以播放网络音频,但其实际上是将音频文件下载到本地后再播放的. 本文演示如何使用 ...
- Expression Blend4经验分享:制作一个简单的图片按钮样式
这次分享如何做一个简单的图片按钮经验 在我的个人Silverlight网页上,有个Iphone手机的效果,其中用到大量的图片按钮 http://raimon.6.gwidc.com/Iphone/de ...
- Swift - 制作一个录音机(声音的录制与播放)
1,技术介绍 (1)AVFoundation.framework框架提供了AVAudioRecorder类.它可以实现录音功能. (2)而使用该框架的AVAudioPlayer类,可以实现声音的播放. ...
- css3制作一个漂亮的按钮
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFMAAAA4CAIAAAAO41POAAAGWklEQVRogeWabWwTdRzH/8EwMb6Q69
- 使用 Swift 制作一个新闻通知中心插件(2)
我们在第一部分的文章中详细讲解了创建一个通知中心插件的整体过程.我们成功的在通知中心里面显示了新闻列表.但是截止到目前,我们还不能从通知中心的列表中查看新闻的详细内容.在这次的教程中,我们就以上次的教 ...
随机推荐
- POJ 1423 Big Number
题意:求n阶乘的位数. 解法:斯特林公式,,然后取log10就是位数了,因为精度问题需要化简这个式子,特判1. 代码: #include<stdio.h> #include<iost ...
- 2、列表item_圆头像_信息提示
import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import an ...
- SQL注入中利用XP_cmdshell提权的用法(转)
先来介绍一下子服务器的基本情况,windows 2000 adv server 中文版,据称 打过了sp3,asp+iis+mssql .首先扫描了一下子端口,呵呵,开始的一般步骤. 端口21开放: ...
- 【剑指offer 面试题13】在 O(1) 时间删除链表结点
#include <iostream> using namespace std; //构造链表结点 struct ListNode { int val; ListNode *next; L ...
- java Ant 的使用
Apache Ant 1.7.0 is the best available version的下载地址:http://ant.apache.org/bindownload.cgi 部署: 参考JAVA ...
- asp.net MVC 中@Html.Partial,@Html.Action,@Html.RenderPartial,@Html.RenderAction区别
@Html.Action:需要有对应的Action,并且Action方法有返回值.(注:处理完业务逻辑同时,也需要返回所需值) @{Html.RenderAction}:需要有对应的Action,Ac ...
- 关于tomcat不支持put方式的解决方式
在jetty中是支持put方式操作的,在tomcat中默认是不支持的,解决方式很简单,在web.xml中添加一个过滤器即可. <filter> <filter-name>htt ...
- 阿里云slb http https配置
- homework 08_2 C++11新特性作业之二
---恢复内容开始--- 1.使用Lambda表达式计算“hello world!”中字母e和i的数量 下面是代码: #include "stdafx.h" #include< ...
- JAVA中的常见面试题1
1.线程同步的方法的使用. sleep():使一个正在运行的线程处于睡眠状态,是一个静态方法,调用此方法要捕捉InterruptedException异常. wait():使一个线程处于等待状态,并且 ...