更新时间:2022-12-30 10:19:16
我找到了解决这个问题的方法。其他答案部分正确并且有用。
I found the solution to this problem. Other answers are partially correct and are helpful.
以下几点对于理解解决方案非常重要:
The following points are important to understanding the solution:
为了解决这个问题,我们将不得不自己使用Core Animation,并且不能依赖UIView动画块来为我们工作。
In order to solve, we are going to have to tap into Core Animation ourselves, and can't rely on the UIView animation block to do the work for us.
只需创建一个 CATransaction
,其持续时间与 [UIView animateWithDuration]相同:...]
。这将创建一个单独的动画,但如果您的持续时间和缓动功能相同,它应该与动画块中的其他动画完全一致。
Simply create a CATransaction
with the same duration that you are using with [UIView animateWithDuration:...]
. This will create a separate animation, but if your durations and easing function is the same, it should animate exactly with the other animations in your animation block.
NSTimeInterval duration = 0.5;// match this to the value of the UIView animateWithDuration: call
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:duration] forKey:kCATransactionAnimationDuration];
self.myView.layer.mask.position = CGPointMake(newX, 0);
self.myView.layer.mask.bounds = CGRectMake(0, 0, newWidth, newHeight);
[CATransaction commit];