我希望A调整大小(缩小),所以我将动画添加到我的A层
但是当我提交动画子层B时没有缩小.它的大小仍然存在(但它的位置随着超级层边界的变化而变化)
如何使我的B图层与A动画一起调整大小?
这就是我写的:
CABasicAnimation *fadeInAnimation; fadeInAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"]; fadeInAnimation.repeatCount = 1; fadeInAnimation.autoreverses = NO; fadeInAnimation.fromValue = [NSNumber numberWithfloat:1.0]; fadeInAnimation.tovalue = [NSNumber numberWithfloat:0.0]; CABasicAnimation *shrinkAnimation; shrinkAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"]; shrinkAnimation.repeatCount = 1; shrinkAnimation.autoreverses = NO; shrinkAnimation.timingFunction = [camediatimingFunction functionWithname:kcamediatimingFunctionEaseIn]; shrinkAnimation.tovalue = [NSValue valueWithCGSize:CGSizeMake(0,0)]; aniGroupOFF = [[CAAnimationGroup animation] retain]; aniGroupOFF.delegate = self; aniGroupOFF.duration = ANI_DURATION; aniGroupOFF.animations = [NSArray arrayWithObjects:shrinkAnimation,fadeInAnimation,nil];
提交:
[self addAnimation:aniGroupOFF forKey:@"shrinkAndFade"];self.opacity = 0.0;
回答:
CABasicAnimation *shrinkAnimation; shrinkAnimation = [CABasicAnimation animationWithKeyPath:@"transform"]; //use transform instead of bounds.size shrinkAnimation.repeatCount = 1; shrinkAnimation.autoreverses = NO; shrinkAnimation.timingFunction = [camediatimingFunction functionWithname:kcamediatimingFunctionEaseIn]; shrinkAnimation.tovalue = [NSValue valueWithCAtransform3D:CAtransform3DScale(self.transform,0.1,1.0)]; aniGroupOFF = [[CAAnimationGroup animation] retain]; aniGroupOFF.delegate = self; aniGroupOFF.duration = ANI_DURATION; aniGroupOFF.animations = [NSArray arrayWithObjects:shrinkAnimation,nil];解决方法 实现此目的的最简单方法是为keyPath“transform.scale”设置动画,而不是“bounds.size”.
如果你坚持使用“bounds.size”,你需要在A层的代理上实现A层或layoutSublayersOfLayer:(CALayer *)aLayer上的layoutSublayers,并在该实现中手动调整B的大小.
总结以上是内存溢出为你收集整理的iphone – 调整图层及其子图层的大小 – CoreAnimation全部内容,希望文章能够帮你解决iphone – 调整图层及其子图层的大小 – CoreAnimation所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)