iOS的动画效果类型及实现方法

来源:互联网 发布:oracle数据库分页语句 编辑:程序博客网 时间:2024/06/06 07:37

实现iOS漂亮的动画效果主要有两种方法:
一种是UIView层面的,一种是使用CATransition进行更低层次的控制。
第一种是UIView,UIView方式可能在低层也是使用CATransition进行了封装,它只能用于一些简单的、常用的效果展现,这里写一个常用的示例代码,供大家参考。
[UIView beginAnimations:@”Curl”context:nil];//动画开始
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUpforView:myview cache:YES];
[myview removeFromSuperview];
[UIView commitAnimations];
第二种方式相对复杂一些,但如果更好的进行控制,还是使用这种方法吧,基本使用方法可以看一下如下例子:
CATransition *animation = [CATransition animation];
[animation setDuration:1.25f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setType:kCATransitionReveal];
[animation setSubtype: kCATransitionFromBottom];
[self.view.layer addAnimation:animation forKey:@”Reveal”];
这里使用了setType与setSubtype组合,这使用个比较保险,因为他的参数就是官方API里定义的,他们的参数说明可以参考如下:
[animation setType:@”suckEffect”];
这里的suckEffect就是效果名称,可以用的效果主要有:
pageCurl向上翻一页
pageUnCurl向下翻一页
rippleEffect滴水效果
suckEffect收缩效果,如一块布被抽走
cube立方体效果
oglFlip上下翻转效果
最后再给出一种常用代码供大家参考。
// Curl the image up or down
CATransition*animation = [CATransition animation];
[animationsetDuration:0.35];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
if(!curled)
{
//animation.type =@”mapCurl”;
animation.type = @”pageCurl”;
animation.fillMode =kCAFillModeForwards;
animation.endProgress = 0.99;
} else {
//animation.type =@”mapUnCurl”;
animation.type = @”pageUnCurl”;
animation.fillMode = kCAFillModeBackwards;animation.startProgress = 0.01;
}
[animation setRemovedOnCompletion:NO];
[view exchangeSubviewAtIndex:0withSubviewAtIndex:1];
[view addAnimation:animationforKey”pageCurlAnimation”];

0 0