我找到了解决这一问题的办法。 其他答复部分正确,有帮助。
以下几点对于理解解决办法很重要:
- The mask property is not animatable itself.
- Since the mask is a CALayer it can be animated on its own.
- Frame is not animatable, use bounds and position. This may not apply to you(if you weren t trying to animate the frame), but was an issue for me. (See Apple QA 1620)
- A view layer s mask is not tied to UIView so it will not receive the core animation transaction that is applied to the view s layer.
- We are modifying the CALayer directly, so we can t expect that UIView will have any idea of what we are trying to do, so the UIView animation won t create the core animation transaction to include changes to our properties.
为了解决该问题,我们将不得不利用核心估算本身,并可能依靠国际调查组为我们工作。
简言之,在您使用<代码>的同一期限内,建立。 WithDuration:...]. 这将造成一种单独的估计,但如果你的任期和缓解职能相同,则应当与你的估算组中的其他估算完全一致。
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];