zoukankan      html  css  js  c++  java
  • swift pop实现动感按钮动画

    //
    //  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")
            }
        }
    }
  • 相关阅读:
    gdb 查看变量~p长串末尾省略号, 一个页面显示不完
    Git 在团队中的最佳实践--如何正确使用Git Flow[转]
    apktool+dex2jar+xjad反编译android程序
    浏览器缓存详解:expires,cache-control,last-modified,etag详细说明
    64位windows 7下成功配置TortoiseGit使用Github服务器
    github简单使用教程
    浅淡HTML5移动Web开发
    Surface、SurfaceView、SurfaceHolder及SurfaceHolder.Callback之间的关系
    深入浅出Symfony2
    利用PHP取二进制文件头判断文件类型
  • 原文地址:https://www.cnblogs.com/tian-sun/p/5039118.html
Copyright © 2011-2022 走看看