iphone开发中的各种动画效果
来源:互联网 发布:淘宝点赞买家秀要钱吗 编辑:程序博客网 时间:2024/06/03 21:35
iphone中存在很多好看的动画效果,用于页面的切换等。其中某些是apple私有的,据说私有的无法通过apple的审批。
最近工作中刚好用到过其中的某些动画,所以在网上搜了下资料,了解了下这些动画。这里就自己的理解做一下总结,如有错误或遗漏,尽请谅解。
1、UIView 动画
官方API中,使用UIView可以设置5个动画效果,分别为:
UIViewAnimationTransitionNone 不使用动画
UIViewAnimationTransitionFlipFromLeft 从左向右旋转翻页
UIViewAnimationTransitionFlipFromRight 从右向左旋转翻页,与UIViewAnimationTransitionFlipFromLeft相反
UIViewAnimationTransitionCurlUp 卷曲翻页,从下往上
UIViewAnimationTransitionCurlDown 卷曲翻页,从上往下
详细请参见UIViewAnimationTransition
例子:
[UIViewbeginAnimations:@"animationID"context:nil];//开始一个动画块,第一个参数为动画块标识
[UIViewsetAnimationDuration:0.5f];//设置动画的持续时间
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];//设置动画块中的动画属性变化的曲线,此方法必须在beginAnimations方法和commitAnimations,默认即为UIViewAnimationCurveEaseInOut效果。详细请参见UIViewAnimationCurve
[UIViewsetAnimationRepeatAutoreverses:NO];//设置是否自动反转当前的动画效果
[UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFromLeftforView:self.viewcache:YES];//设置过渡的动画效果,此处第一个参数可使用上面5种动画效果
[self.viewexchangeSubviewAtIndex:1withSubviewAtIndex:0];//页面翻转
[UIViewcommitAnimations];//提交动画
2、公共动画效果
使用CATransiton可以设置4种动画效果,分别为:
NSString * const kCATransitionFade;//渐渐消失
NSString * const kCATransitionMoveIn;//覆盖进入
NSString * const kCATransitionPush;//推出
NSString * const kCATransitionReveal;//与MoveIn相反
例子:
CATransition *animation = [CATransitionanimation];
animation.duration = 0.5f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.type = kCATransitionPush;//设置上面4种动画效果
animation.subtype = kCATransitionFromTop;//设置动画的方向,有四种,分别为kCATransitionFromRight、kCATransitionFromLeft、kCATransitionFromTop、kCATransitionFromBottom
[self.view.layeraddAnimation:animation forKey:@"animationID"];
3、私有动画
iphone种还有很多动画是苹果私有的,例如删除照片的动画等,
私有动画可以直接在animation.type中传入动画的字符串即可。动画有以下几种:
cube:像立方体一样翻转
suckEffect:渐渐缩小,与删除照片动画一样
oglFlip:上下旋转,当subType为fromLeft或者fromRight时,与UIViewAnimationTransitionFlipFromLeft和UIViewAnimationTransitionFlipFromRight一样
rippleEffect:水波效果
pageCurl:与UIViewAnimationTransitionCurlUp一样
pageUnCurl:与UIViewAnimationTransitionCurlDown一样
cameraIrisHollowOpen:First half of cameraIris.
cameraIrisHollowClose:Second half of cameraIris
以上所有动画效果的demo请见http://www.cocoachina.com/bbs/read.php?tid-11820.html,在此感谢楼主的分享,给我的学习带来很到的帮助。
UIViewAnimationState描述:http://www.iphonedevwiki.net/index.php/UIViewAnimationState
同时,本人在使用UIView实现suckEffect缩小的效果过程中遇到一个问题(不知道如何定位),经过搜索终觅得解决方法,分享如下:
[UIViewbeginAnimations:@"suck"context:NULL];
[UIViewsetAnimationTransition:103forView:self.viewcache:YES];
[UIViewsetAnimationDuration:0.5f];
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[UIViewsetAnimationPosition:CGPointMake(44, 42)];
}else {
[UIViewsetAnimationPosition:CGPointMake(320 , 42)];
}
[UIViewcommitAnimations];
其中setAnimationPosition方法就是用于设置缩小点的位置的,此处虽然会报一个警告,但是结果还是正确的。
来自:http://blog.csdn.net/xiaoguan2008/article/details/6291425
来自:http://blog.sina.com.cn/s/blog_7cb1a1c901010gbl.html
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitio
[self.view removeFromSuperview];
[UIView commitAnimations];
=========================================================================================
第一次更新:2012年3月26日10:59:56
=========================================================================================
原来书上有相关动画的设置:
- (IBAction)switchViews:(id)sender {
//声明一个动画块,后面的一些函数都是只有在块中才能有作用,比如setAnimationCurve:
//动画时间
//设置动画曲线,easeInOut : 前后慢,中间快。
//动画形式 ,利用缓存(可以加快运行速度,如果没有特殊要求,参数为YES)