OC学习之UIView动画设置
来源:互联网 发布:网络安全技术是什么 编辑:程序博客网 时间:2024/06/05 18:45
ios各种动画效果
最普通动画:
//开始动画 [UIView beginAnimations:nil context:nil]; //设定动画持续时间 [UIView setAnimationDuration:2]; //动画的内容 frame.origin.x += 150; [img setFrame:frame]; //动画结束 [UIView commitAnimations];连续动画:一个接一个地显示一系列的图像
NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"myImage1.png"], [UIImage imageNamed:@"myImage2.png"], [UIImage imageNamed:@"myImage3.png"], [UIImage imageNamed:@"myImage4.gif"], nil]; UIImageView *myAnimatedView = [UIImageView alloc]; [myAnimatedView initWithFrame:[self bounds]]; myAnimatedView.animationImages = myImages; //animationImages属性返回一个存放动画图片的数组 myAnimatedView.animationDuration = 0.25; //浏览整个图片一次所用的时间 myAnimatedView.animationRepeatCount = 0; // 0 = loops forever 动画重复次数 [myAnimatedView startAnimating]; [self addSubview:myAnimatedView]; [myAnimatedView release];CATransition Public API动画:
CATransition *animation = [CATransition animation]; //动画时间 animation.duration = 0.5f; //先慢后快 animation.timingFunction = UIViewAnimationCurveEaseInOut; animation.fillMode = kCAFillModeForwards; //animation.removedOnCompletion = NO; //各种动画效果 /* kCATransitionFade; kCATransitionMoveIn; kCATransitionPush;z kCATransitionReveal; */ /* kCATransitionFromRight; kCATransitionFromLeft; kCATransitionFromTop; kCATransitionFromBottom; */ //各种组合 animation.type = kCATransitionPush; animation.subtype = kCATransitionFromRight; [self.view.layer addAnimation:animation forKey:@"animation"];CATransition Private API动画:
animation.type可以设定为以下效果
动画效果汇总:
/* suckEffect(三角) rippleEffect(水波抖动) pageCurl(上翻页) pageUnCurl(下翻页) oglFlip(上下翻转) cameraIris/cameraIrisHollowOpen/cameraIrisHollowClose (镜头快门,这一组动画是有效果,只是很难看,不建议使用 而以下为则黑名单: spewEffect: 新版面在屏幕下方中间位置被释放出来覆盖旧版面. - genieEffect: 旧版面在屏幕左下方或右下方被吸走, 显示出下面的新版面 (阿拉丁灯神?). - unGenieEffect: 新版面在屏幕左下方或右下方被释放出来覆盖旧版面. - twist: 版面以水平方向像龙卷风式转出来. - tubey: 版面垂直附有弹性的转出来. - swirl: 旧版面360度旋转并淡出, 显示出新版面. - charminUltra: 旧版面淡出并显示新版面. - zoomyIn: 新版面由小放大走到前面, 旧版面放大由前面消失. - zoomyOut: 新版面屏幕外面缩放出现, 旧版面缩小消失. - oglApplicationSuspend: 像按"home" 按钮的效果. */ UIView Animations 动画: [UIView beginAnimations:@"animationID" context:nil]; [UIView setAnimationDuration:0.5f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationRepeatAutoreverses:NO]; //以下四种效果 /* [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//oglFlip, fromLeft [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];//oglFlip, fromRight [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; */ [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0]; [UIView commitAnimations];IOS4.0新方法:
方法:
+(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;
方法实现:
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; //多一个动画结束后可以执行的操作. //下边是嵌套使用,先变大再消失的动画效果. [UIView animateWithDuration:1.25 animations:^{ CGAffineTransform newTransform = CGAffineTransformMakeScale(1.2, 1.2); [firstImageView setTransform:newTransform]; [secondImageView setTransform:newTransform];} completion:^(BOOL finished){ [UIView animateWithDuration:1.2 animations:^{ [firstImageView setAlpha:0]; [secondImageView setAlpha:0];} completion:^(BOOL finished){ [firstImageView removeFromSuperview]; [secondImageView removeFromSuperview]; }]; }];
- -(void)dochange1
- {
- [UIView beginAnimations:@"animation" context:nil];
- [UIView setAnimationDuration:1.0f];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//翻页路线
- // [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
- // forView:self.view cache:YES];
- // [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
- // forView:self.view cache:YES];
- [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
- forView:self.view cache:YES];
- // [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
- // forView:self.view cache:YES];
- // [UIView setAnimationTransition:UIViewAnimationTransitionNone
- // forView:self.view cache:YES];
- [UIView commitAnimations];
- // BackView *next=[[BackView alloc] init];
- // [self.navigationController pushViewController:next animated:YES];
- }
- -(void)dochange2
- {
- [UIView beginAnimations:@"animation" context:nil];
- [UIView setAnimationDuration:1.0f];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
- //交换本视图控制器中的两个view
- [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:0];
- [UIView setAnimationDidStopSelector:@selector(animationFinish:)];
- [UIView commitAnimations];
- }
- -(void)dochange3
- {
- CATransition *animation=[CATransition animation];
- animation.delegate=self;
- animation.duration=2.0f;//间隔时间
- animation.timingFunction=UIViewAnimationCurveEaseInOut;
- //transition.type的四种类型
- // animation.type=kCATransitionPush;//揭开效果
- // animation.type=kCATransitionFade;//淡化效果
- // animation.type=kCATransitionMoveIn;//推挤效果
- animation.type=kCATransitionReveal;//覆盖效果
- //私有类型动画
- // animation.type=@"cube";//立方体效果
- // animation.type=@"suckEffect";//吸收效果
- // animation.type=@"oglFlip";//翻转效果 //subtype中的right和left效果一样
- // animation.type=@"rippleEffect";//波纹效果
- // animation.type=@"pageCurl";//翻页效果
- // animation.type=@"pageUnCurl";//反翻页效果
- // animation.type=@"cameraIrisHollowOpen";//镜头开效果
- // animation.type=@"cameraIrisHollowClose";//镜头关效果
- // animation.type=@"puzzle";
- animation.subtype=kCATransitionFromTop;//从上面
- // animation.subtype=kCATransitionFromBottom;//从下面
- // animation.subtype=kCATransitionFromLeft;//从左边
- // animation.subtype=kCATransitionFromRight;//从右边
- [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
- [self.view.layer addAnimation:animation forKey:@"animation"];
- }
- OC学习之UIView动画设置
- oc新手学习细节之(UIView)动画总结
- 动画之UIView动画
- ios 学习总结之UIView的动画
- UIView动画设置
- OC-UIImage动画&UIImageView动画&UIView动画NSTimer动画
- UIView动画学习笔记
- UIView 动画基本学习
- iOS之UIView动画
- 【Swift学习ing】之 UIView动画(基础篇)
- UIView动画(学习笔记)
- iOS 学习笔记 UIView动画
- IPhone之UIView中动画
- IPhone之UIView中动画
- IPhone之UIView中动画
- iOS动画之UIView实现
- IOS开发之UIView动画
- SG之UIView基本动画
- 题目1074:对称平方数
- Go语言学习2:第一个go程序
- tomcat集成apr
- 零死角玩转STM32---阅读摘记二
- HDU 4628 Pieces 解题报告
- OC学习之UIView动画设置
- ubuntu 安装svn
- 设备驱动模型
- hdu 4630 No Pain No Game 线段树 树状数组
- VC学习之类的类成员初始化
- codeforces 313C. Ilya and Matrix
- 题目1124:Digital Roots
- 走马灯(四个方格循环移动)
- 2013 Multi-University Training Contest 3