1.UIView动画(块)——(指过渡效果的动画)
UIView视图的动画功能,可以使在更新或切换视图时有放缓节奏、产生流畅的动画效果,进而改善用户体验。UIView可以产生动画效果的变化包括:
示例代码:
位置变化:在屏幕上移动视图。
- 大小变化:改变视图框架(frame)和边界。
- 拉伸变化:改变视图内容的延展区域。
- 改变透明度:改变视图的alpha值。
- 改变状态:隐藏或显示状态。
- 改变视图层次顺序:视图哪个前哪个后。
- 旋转:即任何应用到视图上的仿射变换(transform)。
1 [UIView beginAnimations:nil context:nil];
2 //setAnimationCurve来定义动画加速或减速方式
3 [UIView setAnimaitonCurve:UIViewAnimationCurveLine ar];
4 [UIView setAnimationDuration:2.7]; //动画时长
5 [UIView setAnimationTransition:transition forView:self.view cache:YES];
6 // operation>>>
7 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
8 // end<<<<<
9 [UIView commitAnimations];
1 [UIView beginAnimations:nil context:nil];
2 //setAnimationCurve来定义动画加速或减速方式
3 [UIView setAnimaitonCurve:UIViewAnimationCurveLine ar];
4 [UIView setAnimationDuration:2.7]; //动画时长
5 [UIView setAnimationTransition:transition forView:self.view cache:YES];
6 // operation>>>
7 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
8 // end<<<<<
9 [UIView commitAnimations];
10
1 [UIView beginAnimations:nil context:nil];
2 //setAnimationCurve来定义动画加速或减速方式
3 [UIView setAnimaitonCurve:UIViewAnimationCurveLine ar];
4 [UIView setAnimationDuration:2.7]; //动画时长
5 [UIView setAnimationTransition:transition forView:self.view cache:YES];
6 // operation>>>
7 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
8 // end<<<<<
9 [UIView commitAnimations];
10
基本动画效果:
UIViewAnimationTransitio nNone 正常
UIViewAnimationTransitio nFlipFromLeft 从左向右翻
UIViewAnimationTransitio nFlipFromRight 从右向左翻
UIViewAnimationTransitio nCurlUp 从下向上卷
UIViewAnimationTransitio nCurlDown 从上向下卷
2 //setAnimationCurve来定义动画加速或减速方式
3 [UIView setAnimaitonCurve:UIViewAnimationCurveLine
4 [UIView setAnimationDuration:2.7]; //动画时长
5 [UIView setAnimationTransition:transition forView:self.view cache:YES];
6 // operation>>>
7 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
8 // end<<<<<
9 [UIView commitAnimations];
1 [UIView beginAnimations:nil context:nil];
2 //setAnimationCurve来定义动画加速或减速方式
3 [UIView setAnimaitonCurve:UIViewAnimationCurveLinear];
4 [UIView setAnimationDuration:2.7]; //动画时长
5 [UIView setAnimationTransition:transition forView:self.view cache:YES];
6 // operation>>>
7 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
8 // end<<<<<
9 [UIView commitAnimations];
10
2 //setAnimationCurve来定义动画加速或减速方式
3 [UIView setAnimaitonCurve:UIViewAnimationCurveLine
4 [UIView setAnimationDuration:2.7]; //动画时长
5 [UIView setAnimationTransition:transition forView:self.view cache:YES];
6 // operation>>>
7 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
8 // end<<<<<
9 [UIView commitAnimations];
10
UIViewAnimationTransitio
UIViewAnimationTransitio
UIViewAnimationTransitio
UIViewAnimationTransitio
2.core方式:使用CATransition类
iPhone还支持Core Animation作为其QuartzCore架构的一部分,CA API为iPhone应用程序提供了高度灵活的动画解决方案。但是须知:CATransition只针对图层,不针对视图。图层是Core Animation与每个UIView产生联系的工作层面。 使用Core Animation时,应该将CATransition应用到视图的默认图层( [myView layer] ) 而不是视图本身。
使用CATransition类实现动画,只需要建立一个Core Animation对象,设置它的参数,然后把这个带参数的过渡添加到图层即可。
使用要引入QuartzCore.framework
示例代码:
1 CATransition *transition = [CATransition animation];
2 transition.duration = 0.7;
3 transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
4 transition.type = kCATransitionMoveIn;//{kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade};
5
6 //更多私有{@"cube",@"suckEffect",@"oglFlip",@"rippleEffect",@"pageCurl",@"pageUnCurl",@"cameraIrisHollowOpen",@"cameraIrisHollowClose"};
7 transition.subtype = kCATransitionFromLeft;//{kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom};
9 transition.delegate = self;
10 [self.view.layer addAnimation:transition forKey:nil]; 12 // 要做的
13 [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
动画嵌套使用:
[UIView CGAffineTransform [firstImageView [secondImageView completion:^(BOOL [UIView [firstImageView [secondImageView [firstImageView [secondImageView }]; |