• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

swiftpop实现动感按钮动画

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
//
//  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")
        }
    }
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Swift版sharesdk第三方登录facebook,推特,googleplus集成全教程发布时间:2022-07-18
下一篇:
Swift结构体和类发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap