I have a subclass of UIView that overrides drawRect. Within it, I'm using CGBlendModes to give a coin graphic a visual effect. Works like a charm (no pun intended ha ha). I would like to animate the CGContextSetFillColor alpha property within drawRect to give the look of the coin pulsing/glowing.
Here is what I have:
class CoinView: UIView {
override func drawRect(rect: CGRect) {
let largeCoin = UIImage(named: "coin")!
let context: CGContextRef = UIGraphicsGetCurrentContext()!
var testAlpha:CGFloat = 1.0
CGContextSetFillColor(context, CGColorGetComponents(UIColor(red: 191/255, green: 217/255, blue: 56/255, alpha: testAlpha).CGColor))
CGContextClipToMask(context, rect, largeCoin.CGImage)
CGContextFillRect(context, rect)
largeCoin.drawInRect(rect, blendMode: CGBlendMode.ColorBurn, alpha: 1.0)
UIView.animateWithDuration(5.0) {
testAlpha = 1.0
}
}
}
I tried writing an animation block within drawRect that animates the alpha property (testAlpha) of the CGBlendMode.
Nothing happens. The animation does not fire at all. The CGContextSetFillColor method provides the visual effect, so I thought it'd work trying to animate that.
Any pointers here are appreciated. How do I give the image a "pulse" effect with CGBlendMode.
Thanks