【发布时间】:2013-11-10 17:32:25
【问题描述】:
我有一个CircleView : UIView 类,当您触摸它时(通过pop 函数),它会产生动画(收缩和增长)。当你触摸它时,我还希望一个描边的圆圈出现并长出来(就像一个基本的水波纹)。 (我说的效果如图here in CSS)
我该怎么做呢?
更多信息:
- 理想情况下,两个动画都可以通过单个
CircleView类进行控制 -
CircleView继承UIView
更新
根据答案,我通过subLayer 添加了一个新对象。这显示正常,但在pop 期间没有动画。谁能帮我理解为什么?
这是我当前的代码(无论如何都是相关的)
- (void)layoutSubviews
{
[self setLayerProperties];
}
- (void)setLayerProperties {
//The view’s Core Animation layer used for rendering.
CAShapeLayer *layer = (CAShapeLayer *)self.layer;
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:self.frame.size];
layer.path = bezierPath.CGPath;
layer.fillColor = _Color.CGColor;
rippleLayer = [[CALayer alloc] init];
layer.path = bezierPath.CGPath;
layer.strokeColor = [UIColor blueColor].CGColor;
[layer addSublayer:rippleLayer];
}
// Does the animated "pop"
- (void)pop{
CABasicAnimation *animation = [self animationWithKeyPath:@"transform.scale"];
[animation setFromValue:[NSNumber numberWithFloat:1.0f]];
[animation setToValue:[NSNumber numberWithFloat:0.8f]];
[animation setRemovedOnCompletion:YES];
[animation setDuration:0.15];
[animation setAutoreverses:YES];
[self.layer addAnimation:animation forKey:animation.keyPath];
rippleLayer.anchorPoint = CGPointMake(1, 1);
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
[scale setFromValue:[NSNumber numberWithFloat:1.0f]];
[scale setToValue:[NSNumber numberWithFloat:2.0f]];
[scale setRepeatCount:1];
[scale setDuration:1.0f];
//r[scale setRemovedOnCompletion:YES];
[scale setFillMode:kCAFillModeForwards];
[rippleLayer addAnimation:scale forKey:scale.keyPath];
}
【问题讨论】:
-
你可以在动画块内做很多事情,你不局限于只调整一个属性。如果您想要的第二个效果符合时间限制,只需在此处进行多条声明即可。否则尝试连续调用多个动画,该方法不会等待每个完成块,它会按顺序将它们全部关闭,之间有毫秒延迟。对于许多效果而言,这种延迟与同时发生的效果完全没有区别。
-
谢谢 Ryan,我知道我可以在动画块中做多极的事情,我想真正的问题是如何添加另一个“对象”来制作动画?
-
通常,您调用动画的视图将是您正在制作动画的许多子视图的父视图。您的示例正在为自己设置动画,但您可以为您引用的任何对象的任何属性设置动画(假设它是可动画的属性......)
-
即。 self.someProperty.somePropertyWhichIsAView.frame = etc...那种东西
-
@ryancumley 请查看我更新的问题,谢谢
标签: ios objective-c uiview cashapelayer animatewithduration