在iPhone中动画过度非常简单.
首先获取当前的图形上下文:
- CGContextRef context = UIGraphicsGetCurrentContext();
接着设置一些动画属性用于开始动画:
- [UIView beginAnimations:nil context:context];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:1.0];
然后设置想要过度的对象的最终状态.
- [big setFrame:SMALLRECT];
- [big setAlpha:0.5];
- [little setFrame:BIGRECT];
- [little setAlpha:1.0];
最后提交动画,这样一个动画就会自动生成了
- [UIView commitAnimations];
其中,setAnimationCurve是设置动画的方式,他有下面集中方式:
- UIViewAnimationCurveEaseInOut //开始和结束时动画效果比较慢
- UIViewAnimationCurveEaseIn //开始动画效果比较慢
- UIViewAnimationCurveEaseOut //结束动画效果比较慢
- UIViewAnimationCurveLinear //平滑的动画效果
- // Start Animation Block
- //CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextRef context = nil;
- [UIView beginAnimations:nil context:context];
- [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:1.0];
- // Animations
- [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
- // Commit Animation Block
- [UIView commitAnimations];
- typedef enum {
- UIViewAnimationTransitionNone,
- UIViewAnimationTransitionFlipFromLeft,
- UIViewAnimationTransitionFlipFromRight,
- UIViewAnimationTransitionCurlUp,
- UIViewAnimationTransitionCurlDown,
- } UIViewAnimationTransition;
除了这种简单的动画方式外,其实还有一种利用QuartzCore来做过度动画.不同的地方在于,这个过度动画作用于层,换句话说,他动画直接做用于整个UIView,而不像UIView的动画,可以作用于UIView局部或本身.当UIView作用与本身时,实际上也就相当于是对层的动画了.
- CATransition *animation = [CATransition animation];
- [animation setDelegate:self];
- [animation setDuration:1.0f];
- [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
- [animation setType: kCATransitionMoveIn];
- [animation setSubtype: kCATransitionFromBottom];
- [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
- [[[self superview] layer] addAnimation:animation forKey:@"transitionViewAnimation"];
setDuration:和UIView中的动画效果一样,持续时间.
setTimingFunction:是动画的种类,和UIView一样,比如匀速动画,快速开始结束等.
setType:是指定动画的类型,他有:
- kCATransitionFade (淡入淡出来补给动画)
- kCATransitionMoveIn(从一个方向覆盖的方式来补给动画)
- kCATransitionPush(推送的方式来补给动画)
- kCATransitionReveal(一个试图展现出另外另外一个试图的方式)
- kCATransitionFromRight
- kCATransitionFromLeft
- kCATransitionFromTop
- kCATransitionFromBottom
- // Curl the image up or down. This runs only on the iPhone and will not
- // produce any effect from the simulator
- CATransition *animation = [CATransition animation];
- [animation setDelegate:self];
- [animation setDuration:1.0f];
- [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
- [animation setType:(notCurled ? @"pageCurl" : @"pageUncurl")];
- /*
- mapCurl, mapUncurl
- pageCurl, pageUncurl
- suckEffect, spewEffect,
- cameraIris, cameraIrisHollowOpen, cameraIrisHollowClose
- genieEffect, unGenieEffect,
- rippleEffect,
- twist,
- tubey,
- swirl,
- charminUltra
- zoomIn, zoomOut
- oglFlip
- */
- //让他不给删除掉
- [animation setRemovedOnCompletion:NO];
- [animation setFillMode: @"extended"];
- [animation setRemovedOnCompletion: NO];
- notCurled = !notCurled;
- [[[self.view viewWithTag:TOP_LAYER_VIEW] layer] addAnimation:animation forKey:@"pageFlipAnimation"];
网名:@"老舟"
兴趣:@"影音,阅读"
动态:@"系统架构设计,Android通信模块开发"
网址:@"http://kilonet.cnblogs.com"
签名:@"--------------------------------------------------
Stay Hungry , Stay Foolish
求 知 若 渴,处 事 若 愚
--------------------------------------------------"
]; // Never Release