- (void)viewDidLoad {
[super viewDidLoad];
UIButton *m_picButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[m_picButton setTitle:@"click me" forState:UIControlStateNormal];
m_picButton.frame = CGRectMake(50, 100, 100, 50);
[self.view addSubview:m_picButton];
[m_picButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonClicked:(id)sender
{
UIButton *myButton = (UIButton*)sender;
//放大动画
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnimation.duration = 2.0f;
scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(100/65, 150/90, 1)];
scaleAnimation.fillMode=kCAFillModeForwards;
scaleAnimation.removedOnCompletion=NO;
//移动动画
CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
CGMutablePathRef pathRef = CGPathCreateMutable();
CGPathMoveToPoint(pathRef, NULL, CGRectGetMidX(myButton.frame), CGRectGetMidY(myButton.frame));
CGPathAddQuadCurveToPoint(pathRef, NULL, 120, 160, self.view.center.x, self.view.center.y);
moveAnimation.path = pathRef;
moveAnimation.duration = 2.0f;
moveAnimation.removedOnCompletion = NO;
CGPathRelease(pathRef);
//组合动画
CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
groupAnimation.duration = 2.0f;
groupAnimation.removedOnCompletion = NO;
groupAnimation.animations = [NSArray arrayWithObjects:scaleAnimation,moveAnimation,nil];
[myButton.layer addAnimation:groupAnimation forKey:@"allAnimation"];
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:2.0f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myButton cache:NO];
[UIView commitAnimations];
[myButton setBackgroundImage:[UIImage imageNamed:@"poster.png"] forState:UIControlStateNormal];
[myButton setTitle:@"" forState:UIControlStateNormal];
myButton.frame = CGRectMake(0, 0, 100,150);
myButton.center = self.view.center;
}