jn_*_*pdx 3 core-animation objective-c ios
我正在尝试使用Core Animation制作一个简单的动画来绘制一个增长的简单条形图.就像一个进度条.
因此,条形图从x = 0开始,宽度为0,并且增长到适合框架.
但是,当我为bounds.size.width设置动画时,原点被认为是图层的中心,并且它在两个x方向上向外生长,而我希望它的最左边点始终为0,最右边为随动画改变 - 再次像进度条一样.
我是否必须为其他属性设置动画,或者是否存在除bounds.size.width之外的其他内容我应该使用它来实现此目的?
作为参考,这是我现在所拥有的:
CABasicAnimation * animation;
animation = [CABasicAnimation animationWithKeyPath:@"bounds.size.width"];
animation.fromValue = [NSNumber numberWithInt:0];
animation.toValue = [NSNumber numberWithInt:(self.frame.size.width / 2)];
[animation setValue:@"primary_on" forKey:@"animation_key"];
animation.duration = duration;
[primaryMask addAnimation:animation forKey:@"primary_on"];
Run Code Online (Sandbox Code Playgroud)
(primaryMask是一个CALayer)
在这种情况下发生同样的事情:
animation = [CABasicAnimation animationWithKeyPath:@"bounds"];
CGRect oldBounds = CGRectMake(0, 0, 0, self.frame.size.height);
CGRect newBounds = CGRectMake(0, 0, self.frame.size.width / 2, self.frame.size.height);
animation.fromValue = [NSValue valueWithCGRect:oldBounds];
animation.toValue = [NSValue valueWithCGRect:newBounds];
Run Code Online (Sandbox Code Playgroud)
Dav*_*eyl 11
你需要设置
layer.anchorPoint = CGPointZero;
Run Code Online (Sandbox Code Playgroud)
默认情况下,此属性为{0.5,0.5},它是图层的中心.
| 归档时间: |
|
| 查看次数: |
7603 次 |
| 最近记录: |