上下划动可以用类似的方法实现:

#import <UIKit/UIKit.h>@interface Abstruct : UIViewController <UIScrollViewDelegate>{UIImageView* myimageview;NSMutableArray *imgArray;CGPoint FirstPoint;CGPoint SecondPoint;NSInteger Page;BOOL touchMove;
}
@property (retain, nonatomic)  UIImageView* myimageview;
@property (retain, nonatomic)  NSMutableArray *imgArray;
@property NSInteger Page;@end

- (void)viewDidLoad
{[super viewDidLoad];imgArray = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"01-01-1.jpg"],[UIImage imageNamed:@"01-01-2.jpg"],[UIImage imageNamed:@"01-01-3.jpg"],[UIImage imageNamed:@"01-01-4.jpg"],[UIImage imageNamed:@"01-01-5.jpg"],[UIImage imageNamed:@"01-01-6.jpg"],[UIImage imageNamed:@"01-01-7.jpg"],nil];self.navigationItem.title = [NSString stringWithFormat:@"1/%d",[imgArray count]];self.myimageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 44,768, 1004)];[self.myimageview setImage:[imgArray objectAtIndex:Page]];[self.view addSubview:myimageview];}/*=======================================================//触摸事件:点击弹出导航条,左右划动切换经文========================================================*/
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {UITouch *touch = [[event allTouches] anyObject];CGPoint point = [touch locationInView:self.view];FirstPoint = point;touchMove = NO;
}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {UITouch *touch = [touches anyObject];CGPoint point = [touch locationInView:self.view];SecondPoint = point;touchMove = YES;
}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{if(touchMove == NO){}else {if (FirstPoint.x > SecondPoint.x){if(Page < [imgArray count] - 1){Page++;CGContextRef context = UIGraphicsGetCurrentContext();[UIView beginAnimations:nil context:context];[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];[myimageview setAlpha:0.0];[UIView setAnimationDuration:0.05];[UIView commitAnimations];[self performSelector:@selector(ChangeImage) withObject:nil afterDelay:0.1];}else if (Page == [imgArray count] -1) {CGContextRef context = UIGraphicsGetCurrentContext();[UIView beginAnimations:nil context:context];[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];[myimageview setAlpha:0.0];[UIView setAnimationDuration:0.05];[UIView commitAnimations];Page = 0;[self performSelector:@selector(ChangeImage) withObject:nil afterDelay:0.1];}}else {if(Page >= 1){Page--;CGContextRef context = UIGraphicsGetCurrentContext();[UIView beginAnimations:nil context:context];[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];[myimageview setAlpha:0.0];[UIView setAnimationDuration:0.05];[UIView commitAnimations];[self performSelector:@selector(ChangeImage) withObject:nil afterDelay:0.1];}}    }
}/*=======================================================更新图片显示========================================================*/
-(void)ChangeImage{CGContextRef context = UIGraphicsGetCurrentContext();[UIView beginAnimations:nil context:context];[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];[UIView setAnimationDuration:0.5]; //动画长度,单位为秒[self.view setAlpha:1];[myimageview setAlpha:1];[myimageview setImage:[imgArray objectAtIndex:Page]];//[myimageview setAnimationRepeatCount:4]; //设置重复次数
    [UIView commitAnimations];self.navigationItem.title = [NSString stringWithFormat:@"%d/%d",Page+1,[imgArray count]];
}@end

转载于:https://www.cnblogs.com/foxmin/archive/2012/04/13/2445612.html

iPhone开发之UIImageView左右划动切换图片相关推荐

  1. 详解iPhone开发之Objective-C和 C 混编

    详解iPhone开发之Objective-C和 C 混编 2011-07-29 15:47 佚名 互联网 字号:T | T 本文介绍的是详解iPhone开发之Objective-C和C混编,介绍了ip ...

  2. 【无限互联】iOS开发视频教程— 2.8 iPhone开发之swtch语句

    核心内容 1. switch语句语法 2. 防止case穿透,与break结合使用 视频地址:iPhone开发之swtch语句

  3. Android透明到白色滑动渐变,Android开发之Activity全透明渐变切换方法

    Activity全透明渐变切换 类似于Dialog的显示动画效果一样 1. 先设置Acitivity为去透明,在取消掉Activity默认的切换动画 true @color/colorPrimary ...

  4. iphone开发之Google地图实现…

    原文地址:iphone开发之Google地图实现 学习随笔 作者:若水一叶 摘自博文:http://tergol.blog.163.com/blog/static/170695028201081961 ...

  5. iPhone开发之Rotation

    iPhone或iPad可以支持4种朝向     UIInterfaceOrientationPortrait     UIInterfaceOrientationPortraitUpsideDown ...

  6. iphone开发之C++和Objective-C混编

    C++和Objective-C混编(官方文档翻译) 原文网址: http://developer.apple.com/iphone/library/documentation/Cocoa/Concep ...

  7. iPhone开发之SQLite

    现在网站开发和软件开发,数据库的支持是少不了的:在iPhone开发中,作为数据持久化的解决方案中,SQLite是不错的选择,它既轻量占用资源少,又可以方便嵌入到程序中,在一些嵌入式设备中有着广泛使用. ...

  8. 【转载】iPhone开发之NSNotificationCenter(通知)的使用方法

    iPhone软件开发的时候会遇到这种情况:打开APP后会在后台运行某个方法,例如下载文件,下载完成后可能需要调用某个方法来刷新界面,这时候可能没法在下载的函数中回调.NSNotificationCen ...

  9. iPhone开发之-iPhone 安装文件的三种格式

    原文地址:http://www.grubx.org/article.asp?id=284 DEB 其中 deb 格式是 Debian 系统(包含 Debian 和 Ubuntu )专属安装包格式,配合 ...

最新文章

  1. 有关Expander组件的研究——Silverlight学习笔记[33]
  2. 1.1.3 性能指标-速率 带宽 吞吐量
  3. Java 编程下的同步代码块
  4. MySQL-数据库监控初探
  5. Node.js 切近实战(十一) 之实时通讯
  6. 《零基础》MySQL 教程(一)
  7. 练习一下爬虫,使用Selenium包
  8. ADO.NET 2.0 的并行控制与数据存取冲突侦测
  9. C# 程序Hello World
  10. request[limit]取不到前台的值_基于uFUN开发板的心率计(二)动态阈值算法获取心率值...
  11. Spark Streaming实例
  12. AutoCAD的卸载后重新安装,删除注册表的详细过程
  13. PuTTY 下载安装教程
  14. 10分钟认识低代码平台
  15. JAVA中d.x=7是什么意思_JVM配置参数之(-D、-X、-XX的区别)
  16. 参与微软Docs翻译
  17. 51单片机 花样流水灯程序
  18. 分享一个简单粗暴的网赚项目:怎么利用音频赚钱?
  19. 旧区块链思维面临淘汰
  20. 深入理解Java虚拟机垃圾回收机制

热门文章

  1. 【wpf】在win10系统上弹出toast和notification
  2. Luogu 2296 寻找道路
  3. win10开移动热点让手机使用上网
  4. 华硕笔记本之secure boot
  5. 使用SQL Server Management Studio 创建作业备份数据库
  6. python中的下划线用法
  7. DHCP+TFTP+PXE自动网络引导安装Linux操作系统
  8. 莎拉波娃美网新赛服亮相
  9. LeetCode7. 整数反转
  10. c++笔记(8) 指针及动态内存管理