0

我正在使用CABasicAnimation更改边界属性,然后使用它来更改图层的位置属性。是否可以同时进行?有点像改变框架UIView

CGRect oldBounds = mask.bounds;
CGRect newBounds = CGRectMake(0,0, rect.size.width * scale, rect.size.height * scale);
NSLog(@"%@", NSStringFromCGRect(newBounds));
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds"];

animation.fromValue = [NSValue valueWithCGRect:oldBounds];
animation.toValue = [NSValue valueWithCGRect:newBounds];

mask.bounds = newBounds;
[mask addAnimation:animation forKey:@"bounds"];



CGPoint oldPos = mask.position;
CGPoint newPos = CGPointMake(rect.origin.x * scale, rect.origin.y * scale);

CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"position"];

animation2.fromValue = [NSValue valueWithCGPoint:oldPos];
animation2.toValue = [NSValue valueWithCGPoint:newPos];

mask.position = newPos;
[mask addAnimation:animation2 forKey:@"position"];
4

1 回答 1

0

编辑:更改为提供更正确的动画...

您可以一次添加 2 个动画...

像这样:

CALayer * myLayer ;

{
    CABasicAnimation * anim = [ CABasicAnimation animationWithKeyPath:@"position" ] ;
    anim.fromValue = [ NSValue valueWithCGPoint:layer.position ] ;
    [ layer addAnimation:anim forKey:nil ] ;
}

layer.position = <#newPosition#> ;

{
    CABasicAnimation * anim = [ CABasicAnimation animationWithKeyPath:@"bounds" ] ;
    anim.fromValue = [ NSValue valueWithCGRect:layer.bounds ] ;
    [ layer addAnimation:anim forKey:nil ] ;
}

layer.bounds = <#newBounds#> ;
于 2012-08-10T00:23:07.813 回答