本站最新网址:http://www.helmsmansoft.com 欢迎关注
功能代码如下:
在.h文件中定义
NSMutableArray *views;
NSInteger currentPage;
CGPoint startPoint;
- (void)viewDidLoad //重写初始化载入方法 { /* 初始化数据 */ [super viewDidLoad]; self.view.userInteractionEnabled = YES; //开启交互功能 UIImageView *view1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pageone.png"]]; view1.userInteractionEnabled = YES; view1.frame = CGRectMake(0, 0, 320, 460); //设置坐标 UIImageView *view2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pagetwo.png"]]; view2.userInteractionEnabled = YES; view2.frame = CGRectMake(0, 0, 320, 460); UIImageView *view3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pagethr.png"]]; view3.userInteractionEnabled = YES; view3.frame = CGRectMake(0, 0, 320, 460); UIImageView *view4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pagefou.png"]]; view4.userInteractionEnabled = YES; view4.frame = CGRectMake(0, 0, 320, 460); NSMutableArray *muView = [[NSMutableArray alloc] init]; [muView addObject:view1]; [muView addObject:view2]; [muView addObject:view3]; [muView addObject:view4]; [view1 release]; [view2 release]; [view3 release]; [view4 release]; self.views = muView; [muView release]; [self.view addSubview:view1]; //添加视图 //[self.view insertSubview:view1 atIndex:0]; } - (void)turnLeftPage:(UIView *)view //自定义 { //设置type和subtype属性产生不同的动画效果 CATransition *transition = [CATransition animation]; //定义过度动画 transition.duration = 0.75; //持续时间 transition.type = @"pageCurl"; //动画样式 transition.subtype = kCATransitionFromLeft; //方向 [[self.view.subviews objectAtIndex:0] removeFromSuperview]; //移除原视图 [self.view insertSubview:view atIndex:0]; //添加新视图 // [self viewWillDisappear:NO]; [self.view.layer addAnimation:transition forKey:nil]; //动画添加到层 } - (void)turnRightPage:(UIView *)view { CATransition *transition = [CATransition animation]; transition.duration = 0.75; transition.type = @"pageCurl"; transition.subtype = kCATransitionFromRight; [[self.view.subviews objectAtIndex:0] removeFromSuperview]; [self.view insertSubview:view atIndex:0]; // [self viewWillDisappear:YES]; [self.view.layer addAnimation:transition forKey:nil]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint pointone = [touch locationInView:self.view];//获得初始的接触点 self.startPoint = pointone; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint pointtwo = [touch locationInView:self.view]; //获得滑动后最后接触屏幕的点 if(fabs(pointtwo.x-startPoint.x)>50){ //判断亮点间的距离 if(pointtwo.x-startPoint.x>0){ //判断点的位置关系 --currentPage; if(self.currentPage >= 0){ //判断页码 UIImageView *nextView = [self.views objectAtIndex:currentPage]; //初始化下一页 [self turnLeftPage:nextView]; //调用自定义方法 }else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告!" message:@"已经到第一页了" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil]; [alert show]; //画警告 [alert release]; self.currentPage = 0; } }else{ ++currentPage; if(self.currentPage < [self.views count]){ UIImageView *nextView = [self.views objectAtIndex:currentPage]; [self turnRightPage:nextView]; }else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告!" message:@"已经是最后一页了" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil]; [alert show]; [alert release]; self.currentPage = [self.views count]-1; } } } }这里使用了setType与setSubtype组合,这使用个比较保险,因为他的参数就是官方API里定义的,他们的参数说明可以参考如下: setType:可以返回四种类型: kCATransitionFade淡出 kCATransitionMoveIn覆盖原图 kCATransitionPush推出 kCATransitionReveal底部显出来 setSubtype:也可以有四种类型: kCATransitionFromRight; kCATransitionFromLeft(默认值) kCATransitionFromTop; kCATransitionFromBottom 还有一种设置动画类型的方法,不用setSubtype,只用setType [animation setType:@"suckEffect"]; 这里的suckEffect就是效果名称,可以用的效果主要有: pageCurl 向上翻一页 pageUnCurl 向下翻一页 rippleEffect 滴水效果 suckEffect 收缩效果,如一块布被抽走 cube 立方体效果 oglFlip 上下翻转效果
发表评论
-
用UITableViewCell实现电子书平铺书架效果
2011-09-16 11:26 2031原创文章,如需转载请注明:转载自:舵手程序 http://ww ... -
遍历指定目录下的文件,将复合条件的文件加载到列表(UITableView))
2011-08-22 09:10 1858本站最新网址:[url]http://www.helmsman ... -
遍历目录下指定文件类型的文件,并输出
2011-08-17 17:54 1338[super viewDidLoad]; ... -
(转)UIApplication sharedApplication
2011-08-17 16:14 1948iPhone应用程序是由主函数main启动,它负责调用UIAp ... -
隐藏UINavigation
2011-08-17 11:05 578在需要的地方设置即可 [self.navigat ... -
在状态栏中添加Activity Indicator View 图标
2011-08-16 15:49 1458添加此属性即可: [UIApplic ... -
实现UIImage的移动动画
2011-08-16 09:28 2408- (void)viewDidLoad { ... -
UIAlertView的基本操作
2011-08-15 17:59 1326UIAlertView 提示框 定义并显示: ... -
在UIAlertVIew 中 添加 UITextField
2011-08-15 17:23 1531UIAlertView *alert = [[UIA ... -
表UITableViewController 的一些操作方法
2011-08-15 16:47 1049是否可以对表进行编辑 [self.tableView se ... -
数组基础
2011-08-15 15:43 8591、创建数组 NSArray *array = [[NSA ... -
UINavigationController,UIBarButtonItem应用的例子
2011-08-12 17:23 1428rootViewController.m文件 - (v ... -
创建一个简单表-UITableView
2011-08-11 14:35 11341.创建基于View-based Application的工 ... -
UIImageView 从左到右出现的动画效果
2011-08-11 11:47 2477UIImageView *imgView =[[UII ...
相关推荐
利用CATransition-给push控制器添加丰富的动画效果
CATransition动画,一些CATransition的简单运用,非常简单的运用
主要为大家详细介绍了iOS基于CATransition实现翻页、旋转等动画效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
iOS中比较全的翻转过渡动画(不只是苹果提供的)。包括(翻页效果、水滴效果、收缩效果、立方体效果、相机镜头打开和关闭效果等等。 也可以去我的github下载:https://github.com/Wheat-Qin/CATransition_Demo
利用CATransition制作的一个图片轮播,这里是通过监控手势的上下走势来控制图片的上下轮播,初步就做到功能后面在进行优化和升级。这是我的gti上对应的地址:https://github.com/tangyi1234/pictureDy.git
CATransition动画主要在过渡时使用,比如两个页面层级改变的时候添加一个转场效果。CATransition分为两类,...这篇文章主要给大家介绍了关于如何利用Swift实现各类CATransition动画的相关资料,需要的朋友可以参考下。
xcode6.3编译,通过swift语言代码方式编写页面跳转动画
简单的转场动画
今天主要用到的动画类是CALayer下...#pragma CATransition动画实现 - (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIView *) view { //创建CATransition对象 CATransit
如:UINavigationController导航控制器就是通过CATransition转场动画实现了将控制器的视图推入屏幕的动画效果 CATransition头文件 动画属性: type:动画过渡类型 subtype:动画过渡方向 startProgress:动画起点...
这是我在学习ios的过程中写的一个demo,使用CATransition实现转场动画效果。
* 各种动画效果 其中除了'fade', `moveIn', `push' , `reveal' ,其他属于似有的API(我是这么认为的,可以点进去看下注释). * ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', '...
UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果 属性解析: type:动画过渡类型 subtype:动画过渡方向 startProgress:动画起点(在整体动画的百分比) endProgress:动画终点(在...
iOS CATransition 详细使用文档
1.这是用catransition实现的动画 2.这个动画执行一半,点灰色部分再回到初始状态
UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果 属性解析: type:动画过渡类型 subtype:动画过渡方向 startProgress:动画起点(在整体动画的百分比) endProgress...
作者Wheat-Qin,源码CATransition_Demo,iOS中比较全的翻转过渡动画(不只是苹果提供的)。包括(翻页效果、水滴效果、收缩效果、立方体效果、相机镜头打开和关闭效果等等。
可帮助你更加熟练页面间的跳转
源码NRTextTransitions,NRTextTransitions可轻松处理UILabel、UITextView以及UITextField中的文本过渡动画。NRTextTransitions使用了和UIView类方法相似的API。 Basic, block based, text transitions ...