开发者

Core Animation and drawRect:

开发者 https://www.devze.com 2023-01-20 02:15 出处:网络
I have a UITableViewCell drawn using drawRect:. I\'m drawing an shape in drawRect and would like to animate this shape (using some parameter) when using the cell goes into edit mode.

I have a UITableViewCell drawn using drawRect:. I'm drawing an shape in drawRect and would like to animate this shape (using some parameter) when using the cell goes into edit mode.

However, I couldn't find how to use animated parameters within drawRect. Could someone point me to the right documentation or is it impossible?

Thank开发者_高级运维s!


Look into using CAShapeLayer for making shapes, it has an animatable property path.

CAShapeLayer* shape = [CAShapeLayer layer];
// Changing this will implicitly animate to new path
shape.path = [UIBezierPath bezierPathWithOvalInRect:someRect].CGPath;
shape.fillColor = [UIColor redColor].CGColor;

For more control over the animation, use CATransaction.


You're not clear on what kind of shape and what kind of animation. If you just need a basic shape such as a square, rectangle, or circle, you could avoid overriding drawRect and just use a CALayer--adding it to your cell's layer hierarchy. For other shapes, you can do the same with a shape layer.

You should consider drawRect for drawing view contents not for animating. It's fine if you want to render the view with drawRect, but if you're just going to move the shape, animate the view's center or the layer's position instead.

If you want to use Core Animation with drawRect (I would recommend against it), you will probably have to animate a custom property that you'll use in your drawRect, but I'm betting what you're trying to do can be done simpler without drawRect. Layers are your friend and can help you in a lot of situations. Maybe elaborate on what you're trying to do and someone can offer you a more complete solution.

Best Regards.

0

精彩评论

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