尝试使用 CAAnimationGroup 放大和缩小 UIButton 时出现问题
Posted
技术标签:
【中文标题】尝试使用 CAAnimationGroup 放大和缩小 UIButton 时出现问题【英文标题】:A problem when try to zoom in & out of UIButton with CAAnimationGroup 【发布时间】:2011-05-22 10:09:11 【问题描述】:没有动画,因为我做的不对?
-(void)swipeanimateDidStop
for (UIView *subview in self.swipingCell.backView.subviews)
NSLog(@"%@",subview);
// subview is UIButton
[subview.layer addAnimation:[self ZoomAnimation] forKey:@"Zoom"];
-(CAAnimationGroup *)ZoomAnimation
CAAnimationGroup *ZoomAnimation = [CAAnimationGroup animation];
CABasicAnimation *In = [self zoomIn];
ZoomAnimation.animations = [NSArray arrayWithObjects: In, nil];
ZoomAnimation.duration = 2.0f;
return ZoomAnimation;
-(CABasicAnimation *)zoomIn
CABasicAnimation *ZoomInAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
ZoomInAnimation.beginTime = 0.0f;
ZoomInAnimation.fromValue = [NSNumber numberWithFloat:20.0];
ZoomInAnimation.toValue = [NSNumber numberWithFloat:1.0];
ZoomInAnimation.duration = 2.0f;
return ZoomInAnimation;
【问题讨论】:
【参考方案1】:错误在zoomIn
方法中。关键路径应该是transform.scale
(因为它是缩放)。
CABasicAnimation *ZoomInAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
【讨论】:
以上是关于尝试使用 CAAnimationGroup 放大和缩小 UIButton 时出现问题的主要内容,如果未能解决你的问题,请参考以下文章
CAAnimationGroup 的最大持续时间值 (CFTimeInterval) 是多少?
使用 CAAnimationGroup 对两个核心动画进行分组会导致一个 CABasicAnimation 无法运行
iOS 旋转动画在 CAAnimationGroup 中发生不顺畅