2012-08-27 59 views
0

我试图实现以下的动画:的UIView组动画

yourSubView.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
//change time duration according to requirement 
// animate it to the identity transform (100% scale) 
yourSubView.transform = CGAffineTransformIdentity; 
} completion:^(BOOL finished){ 
// if you want to do something once the animation finishes, put it here 
}]; 

与子视图的一些运动相结合。我知道核心动画你可以结合动画,但你怎么能在UIView动画中做到这一点?

我可以将此代码从UIView动画转换为Core动画吗?

yourSubView.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
//change time duration according to requirement 
// animate it to the identity transform (100% scale) 
yourSubView.transform = CGAffineTransformIdentity; 
} completion:^(BOOL finished){ 
// if you want to do something once the animation finishes, put it here 
}]; 

回答

2

您可以通过更改多个动画属性来合并动画。例如,您也可以设置您的SubView.alpha,然后更改动画块中的Alpha。它将规模和阿尔法变化结合在一起。

做一个简单的翻译,试试这个在你的动画块:

yourSubView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 100.0, 100.0); 

这应该与移动在X和Y方向100像素沿着设定比例回身份。

对于核心动画,这个Grouping two Core Animations with CAAnimationGroup causes one CABasicAnimation to not run应该让你开始。您将使用CAAnimationGroup合并多个动画,并且可以执行包括3D旋转在内的漂亮功能。

规范化:

CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"]; 
[scale setValues:[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.01f],[NSNumber numberWithFloat:1.0f],nil]]; 
[scale setKeyTimes:[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:0.4f],nil]]; 

[mySubview.layer addAnimation:scale forKey:@"myScale"]; 
+0

代码如何可以转换到核心动画:yourSubView.transform = CGAffineTransformMakeScale(0.01,0.01); [UIView的animateWithDuration:0.4延迟:0选项:UIViewAnimationOptionCurveEaseOut动画:^ {根据需要 //变化持续时间 //它动画的恒等变换(100%比例) yourSubView.transform = CGAffineTransformIdentity; }完成:^(BOOL完成){ //如果您想在动画完成后执行某些操作,请将其放在这里 }]; – Juan

+0

编辑答案显示缩放的例子 – CSmith