iPhone 简单动画过度

在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         //平滑的动画效果
而,setAnimationDuration则是设置动画的持续时间.

下面是两个UIView之间的动画过度
        // 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];
 
页面之间的过度主要依靠 UIView setAnimationTransition: forView: cache: 这个方法以及 exchangeSubviewAtIndex: withSubviewAtIndex:
前者通过UIView静态方法设置过度的动画种类,后者实现真正的过度函数掉用.种类有如下五种:

 

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:是指定动画的类型,他有:

 

  1. kCATransitionFade (淡入淡出来补给动画)
  2. kCATransitionMoveIn(从一个方向覆盖的方式来补给动画)
  3. kCATransitionPush(推送的方式来补给动画)
  4. kCATransitionReveal(一个试图展现出另外另外一个试图的方式)
当除了第一种方式外(淡入淡出),可以通过setSubType:来制定动画的方向(因为这些动画都是直接着用于层的,所以相当于只有试图间的切换过渡).动画方向有4个:
  1. kCATransitionFromRight
  2. kCATransitionFromLeft
  3. kCATransitionFromTop
  4. 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"];
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值