博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
swift pop实现动感按钮动画
阅读量:5998 次
发布时间:2019-06-20

本文共 1900 字,大约阅读时间需要 6 分钟。

//
//  MyButton.swift
//  PopInstall
//
//  Created by su on 15/12/11.
//  Copyright © 2015年 tian. All rights reserved.
//
import UIKit
class MyButton: UIButton {
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        super.touchesBegan(touches, withEvent: event)
        //缩放动画
        var scale = self.pop_animationForKey("scale") as? POPSpringAnimation
        if scale != nil {
            scale?.toValue = NSValue(CGPoint: CGPointMake(0.8, 0.8))
        } else {
            scale = POPSpringAnimation(propertyNamed: kPOPViewScaleXY)
            scale?.toValue = NSValue(CGPoint: CGPointMake(0.8, 0.8))
            scale?.springBounciness = 20
            scale?.springSpeed = 18
            self.pop_addAnimation(scale, forKey: "scale")
        }
       
        //旋转动画  旋转是layer层动画
        var rotate = self.layer.pop_animationForKey("ratate") as? POPSpringAnimation
        if rotate != nil {
            rotate?.toValue = M_PI / 6
           
        } else {
            rotate = POPSpringAnimation(propertyNamed: kPOPLayerRotation)
            rotate?.toValue = M_PI / 6
            rotate?.springBounciness = 20
            rotate?.springSpeed = 18
            self.layer.pop_addAnimation(rotate, forKey: "ratate")
        }
    }
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        super.touchesEnded(touches, withEvent: event)
        //缩放动画
        var scale = self.pop_animationForKey("scale") as? POPSpringAnimation
        if scale != nil {
            scale?.toValue = NSValue(CGPoint: CGPointMake(1, 1))
        } else {
            scale = POPSpringAnimation(propertyNamed: kPOPViewScaleXY)
            scale?.toValue = NSValue(CGPoint: CGPointMake(1, 1))
            scale?.springBounciness = 20
            scale?.springSpeed = 18
            self.pop_addAnimation(scale, forKey: "scale")
        }
        //旋转动画  旋转是layer层动画
        var rotate = self.layer.pop_animationForKey("ratate") as? POPSpringAnimation
        if rotate != nil {
            rotate?.toValue = 0
        } else {
            rotate = POPSpringAnimation(propertyNamed: kPOPLayerRotation)
            rotate?.toValue = 0
            rotate?.springBounciness = 20
            rotate?.springSpeed = 18
            self.layer.pop_addAnimation(rotate, forKey: "ratate")
        }
    }
}

转载于:https://www.cnblogs.com/tian-sun/p/5039118.html

你可能感兴趣的文章
ajax的使用
查看>>
Long,String类型的两个值进行比较,注意点!!!
查看>>
BZOJ1785[USACO 2010 Jan Gold 3.Cow Telephones]——贪心
查看>>
一道面试题
查看>>
CSS中a标签样式的“爱恨”原则
查看>>
第5次作业+105032014138+牟平
查看>>
mysql + unidac 使用事务例子
查看>>
dao封装hql查询list_1
查看>>
抽屉之Tornado实战(4)--发帖及上传图片
查看>>
easyUI解析原理
查看>>
The Princess and the Pea,摘自iOS应用Snow White and more stories
查看>>
链栈和链队列的建立及基本操作
查看>>
百度cdn资源公共库共享及常用开发接口
查看>>
vue教程1-04 事件 v-on:click="函数"
查看>>
sys.argv[]
查看>>
用进程名做参数杀进程
查看>>
[20180718]拷贝数据文件从dg库.txt
查看>>
ROS使用rqt_console
查看>>
vad词根
查看>>
跟随我在oracle学习php(48)
查看>>