我想做一个响应设备运动的动画,即使 UI 线程暂时繁忙,我也希望它保持流畅。动画包括更改 CALayer 的贝塞尔路径。我尝试过从辅助线程执行此操作,但我偶尔会在主线程有一个废弃堆栈的地方挂起。我正在做的事情完全没有希望吗?这是我在线程中所做的:
[CATransaction lock];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
[CATransaction begin];
myLayer.path = [UIBezierPath bezierPathWithOvalInRect:theRect].CGPath;
myLayer.bounds = theBounds;
[CATransaction commit];
[CATransaction flush];
[CATransaction setValue:(id)kCFBooleanFalse
forKey:kCATransactionDisableActions];
[CATransaction unlock];