码迷,mamicode.com
首页 > 其他好文 > 详细

第七篇、使用UIView的animateWithDuration方法制作简易动画

时间:2016-09-19 19:19:29      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

 

技术分享

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(width: 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)
    }
    
}

 

第七篇、使用UIView的animateWithDuration方法制作简易动画

标签:

原文地址:http://www.cnblogs.com/HJQ2016/p/5885990.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!