开发者

iPhone animate Core Graphics

开发者 https://www.devze.com 2022-12-15 08:51 出处:网络
I have a subclass of UIView that draws a number with a border around it using Core Graphics (unread count style). I have this in a UITableViewCell and change the color of the border when setSelected:a

I have a subclass of UIView that draws a number with a border around it using Core Graphics (unread count style). I have this in a UITableViewCell and change the color of the border when setSelected:animated: is called. The problem is that it does not animate the change.

Is there any way on the iPhone to animate the c开发者_C百科hange of Core Graphics drawing. All I want is a simple fade from one state to the other.


Your best bet might be to add a UIImageView to your UIView subclass. Then you can animate the change of the image like so:

[UIView beginAnimations:nil context:NULL];
[imageView setImage:newImage];
[UIView commitAnimations];

Just hold two images for the different color borders and update them to fit when the numbers change. Should only require a bit of rearranging the drawing code.


Try placing another view with the different color border on top, alpha set to 0. Then you fade in the new border and fade out the old border using a UIView animation block. The effect will be a cross fade between the two border colors.


create a CABasicAnimation for opacity; then add it to your CALayer

0

精彩评论

暂无评论...
验证码 换一张
取 消