4

我想在 iPhone 上启动应用程序时复制动画。我认为第一个视图从 50% 放大到 100%。后来我想用它作为两个视图之间的过渡。任何想法如何复制,或者在 sdk 中是否有来自苹果的现成解决方案?非常感谢你 :)

4

2 回答 2

10

你可以用 CABasicAnimation 和 CAAnimationGroup 做同样的事情,我实际上认为 UIKit Animations 上的 Core Animation 更流畅,它给你更多的控制。

CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.removedOnCompletion = YES;

CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnimation.fromValue = [NSNumber numberWithFloat:0.0];
fadeAnimation.toValue = [NSNumber numberWithFloat:1.0];

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat:0.5];
scaleAnimation.toValue = [NSNumber numberWithFloat:1.00];

animationGroup.animations = [NSArray arrayWithObjects:fadeAnimation, scaleAnimation, nil];

[self.layer addAnimation:animationGroup forKey:@"fadeAnimation"];
self.layer.opacity = 1.0;

“给猫剥皮的方法不止一种”

于 2010-08-11T22:29:39.307 回答
6

您可以对 UIView 应用缩放变换,然后将其动画化回正常状态。

// Set the the view's scale to half
[viewToScale setTransform:CGAffineTransformMakeScale(0.5,0.5)];

// Set the transform back to normal (identity) in an animation when you're
// ready to animate
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[viewToScale setTransform:CGAffineTransformIdentity];
[UIView commitAnimations];

诀窍是您需要在动画的单独运行周期中将视图设置为较小的比例,否则您将看不到视图动画。因此,您可以设置较小的比例,然后调用-performSelector:withObject:afterDelay:来实际执行动画。

于 2010-08-05T16:41:26.623 回答