zoukankan      html  css  js  c++  java
  • 第七篇、使用UIView的animateWithDuration方法制作简易动画

    import UIKit
    
    class LolitaCircleButton: UIButton {
        
        private var color: UIColor
        private var imageURL: String
        
        init(color: UIColor , imageURL: String) {
            self.color = color
            self.imageURL = imageURL
            super.init(frame: CGRectZero)
            
            commonInit()
            layer.shadowOpacity = 0.3
            layer.shadowOffset = CGSize( 0.0, height: 0.0)
            layer.shadowRadius = 15
        }
        
        func commonInit() {
            setImage(UIImage(named: self.imageURL)?.imageWithColor(self.color), forState: .Highlighted)
            setImage(UIImage(named: self.imageURL), forState: .Normal)
        }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        override func drawRect(rect: CGRect) {
            super.drawRect(rect)
            let path = UIBezierPath(ovalInRect: rect)
            color.setFill()
            path.fill()
        }
        
        override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
            super.touchesBegan(touches, withEvent: event)
            
            color = UIColor.whiteColor()
            setNeedsDisplay()
            
            UIView.animateWithDuration(0.15) {
                self.transform = CGAffineTransformMakeScale(0.9, 0.9)
            }
        }
        
        override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
            super.touchesEnded(touches, withEvent: event)
            
            color = UIColor.orangeColor()
            setNeedsDisplay()
            
            transform = CGAffineTransformMakeScale(0.0, 0.0)
            
            UIView.animateWithDuration(0.4, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: [], animations: {
                self.transform = CGAffineTransformIdentity
                }, completion: nil)
        }
        
    }
  • 相关阅读:
    day40_jQuery学习笔记_01
    jQuery选择什么版本 1.x? 2.x? 3.x?
    6个关于dd命令备份Linux系统的例子
    快速掌握grep命令及正则表达式
    Linux下删除乱码或特殊字符文件
    在 Linux 中永久修改 USB 设备权限
    CentOS 7 中 hostnamectl 的使用
    申请红帽企业版Linux开发者订阅
    CentOS6 下rsync服务器配置
    Centos6下DRBD的安装配置
  • 原文地址:https://www.cnblogs.com/HJQ2016/p/5885990.html
Copyright © 2011-2022 走看看