我正在尝试为自定义 UIView 的边界设置动画,同时保持其图层与其父视图的大小相同。为此,我试图在其父视图旁边为图层边界设置动画。我需要图层调用 drawLayer:withContext 作为其动画,因此我的自定义绘图将与边界一起正确更改大小。
在我开始动画之前,drawLayer 被正确调用并正确绘制。但是我无法让图层在边界动画的每个步骤上调用其 drawLayer 方法。相反,它只调用一次,立即跳转到动画最后一帧的“结束边界”。
// self.bg is a property pointing to my custom UIView
self.bg.layer.needsDisplayOnBoundsChange = YES;
self.bg.layer.mask.needsDisplayOnBoundsChange = YES;
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{
[CATransaction begin];
self.bg.layer.bounds = bounds;
self.bg.layer.mask.bounds = bounds;
[CATransaction commit];
self.bg.bounds = bounds;
} completion:nil];
为什么边界不报告其动画的变化(不仅仅是最后一帧)?我究竟做错了什么?