【发布时间】:2013-03-11 10:06:25
【问题描述】:
我面临与Animating a shape with CoreAnimation类似的问题
我有一个自定义UIView
MyUIView
- (void)drawRect:(CGRect)rect {
// Right here, I might also draw some triangle, circle which I do not wish
// to be animated.
// ...
// Calculate minX, minY, ... based on rect and self->value.
// ...
// Draw a rounded rectangle based on minX, minY, ...
// The x-location of rounded rectangle will be different for difference self->value
CGContextMoveToPoint(context, minx, midy);
CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
...
...
CGContextDrawPath(context, kCGPathFillStroke);
}
// Usually trigger by controller via button clicked
- (void) setValueViaButtonClicked:(double) value {
self->currentValue = value;
dispatch_async(dispatch_get_main_queue(), ^{
[self setNeedsDisplay];
});
}
目前,每当我单击具有与旧值不同的新值的按钮时,我都可以看到圆角矩形从旧位置移动到新位置,但没有动画。
我想要动画,仅在显式按钮单击期间。对于我见过的大多数示例,动画代码是在控制器中执行的,由
- 动画是通过 Layer 和 CGPathCreateMutable 完成的
- Layer 和 CGPathCreateMutable 的创建在视图控制器中执行。
我想知道,我怎么可能通过MyUIView 的setValueViaButtonClicked 执行上述任务?由于没有来自drawRect的正确rect信息,我将如何配置从CGPathCreateMutable创建的路径的信息?
【问题讨论】: