转自:http://blog.youkuaiyun.com/richard_rufeng/article/details/17500095
第一、实现左右移动
- <span style="font-size:18px;"> [UIView beginAnimations:@"testAnimation" context:@"test"];
- [UIView setAnimationDuration:0.5];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDelegate:self];
- [UIView setAnimationDidStopSelector:@selector(animationStop)];
- CGRect frame=self.myView.frame;
- frame.origin.x=10;
- self.myView.frame=frame;
- [UIView commitAnimations];
- </span>
- <span style="font-size:18px;"> [UIView animateWithDuration:0.5 animations:^{
- CGRect frame=self.myView.frame;
- frame.origin.y=300;
- self.myView.frame=frame;
- //self.myView.alpha=0.0;
- } completion:^(BOOL finished)
- {
- [UIView animateWithDuration:0.5 animations:^{
- //self.myView.alpha=1.0;
- CGRect frame=self.myView.frame;
- frame.origin.y=10;
- self.myView.frame=frame;
- }];
- }];
- </span>
第三、实现渐入渐出得效果
- <span style="font-size:18px;"> [UIView animateWithDuration:0.5 animations:^{
- self.myView.alpha = 0;
- } completion:^(BOOL finished)
- {
- self.myView.alpha = 1;
- }];
- </span>
第四、实现放大缩小
- <span style="font-size:18px;"> self.myView.transform=CGAffineTransformScale(self.myView.transform, 1, 1);
- [UIView animateWithDuration:0.5 animations:^{
- self.myView.transform=CGAffineTransformScale(self.myView.transform, 0.1, 0.1);
- } completion:^(BOOL finished)
- {
- [UIView animateWithDuration:0.5 animations:^{
- self.myView.transform=CGAffineTransformIdentity;
- }];
- }];
- </span>
第五、两个动画间的过渡动画
上面讲的动画是针对一个动画的旋转、平移、放大缩小,我们分析两个动画在切换时的动画效果
- <span style="font-size:18px;"> [UIView beginAnimations:nil context:nil];
- [UIView setAnimationDuration:0.5];
- [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.parentView cache:YES];
- [UIView commitAnimations];
- [self.parentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];</span>
Block方法的实现:
- <span style="font-size:18px;"> [UIView transitionWithView:self.parentView duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
- [self.parentView exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
- } completion:NULL];
- </span>
第六、修改pushviewcontroller切换动画效果
- <span style="font-size:18px;"> [UIView beginAnimations:nil context:nil];
- [UIView setAnimationDuration:0.5];
- [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:YES];
- [UIView commitAnimations];
- UIViewController *viewContr = [[UIViewController alloc] init];
- [self.navigationController pushViewController:viewContr animated:NO];</span>