【发布时间】:2017-11-25 07:56:42
【问题描述】:
我正在尝试为根层上的子层设置动画,该子层附加到目标 C ios 中的 UIView。我已经尝试了许多可用的答案,但子层是固定的,根本没有改变它的位置。
我尝试了以下方法对其进行动画处理:
-(void)moveLayer:(CALayer*)layer to:(CGPoint)point with:(CGRect)bounds
{
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,74.0,74.0);
CAKeyframeAnimation * theAnimation;
// Create the animation object, specifying the position property as the key path.
theAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
theAnimation.path=thePath;
theAnimation.duration=5.0;
// Add the animation to the layer.
[layer addAnimation:theAnimation forKey:@"position"];
}
还有使用
`
[featureLayer setFrame:oldRect];
CGRect oldBounds = oldRect;
CGRect newBounds = faceRect;
CABasicAnimation* revealAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
revealAnimation.fromValue = [NSValue valueWithCGRect:oldBounds];
revealAnimation.toValue = [NSValue valueWithCGRect:newBounds];
revealAnimation.duration = 3.0;
// Update the bounds so the layer doesn't snap back when the animation completes.
featureLayer.bounds = newBounds;
[featureLayer addAnimation:revealAnimation forKey:@"revealAnimation"];
[self.previewLayer setMask:featureLayer];
`
如果有人可以帮助我,那就太好了。提前致谢。
编辑 1
为了确保这是根层上的蒙版图像,我想为蒙版设置动画以从一个位置移动到另一个位置,但它保持静止。
【问题讨论】:
标签: ios objective-c core-animation calayer mask