#define HEIGHT  self.view.frame.size.height

#define WIDTH    self.view.frame.size.width

@interface ViewController : UIViewController<UIScrollViewDelegate>

@property (strong,nonatomic) UIScrollView *myScorolV;

@property (strong,nonatomic) UIPageControl *pageC;

@property (strong,nonatomic) NSMutableArray *arrPage;

@property (strong,nonatomic) UIImageView *threeImage;

@property (strong,nonatomic) UIImageView *secondImage;

@property (strong,nonatomic) UIImageView *firstImage;

@property (assign,nonatomic) int currentPage;

@end

//滚动视图创建

self.myScorolV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];

self.myScorolV.contentSize = CGSizeMake(WIDTH * 3, 0);

self.myScorolV.pagingEnabled = YES;

self.myScorolV.showsHorizontalScrollIndicator = NO;

self.myScorolV.delegate = self;

[self.view addSubview:self.myScorolV];

//分页视图

self.pageC = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH / 5 * 2, HEIGHT - 80, WIDTH / 5, 40)];

self.pageC.backgroundColor = [UIColor clearColor];

self.pageC.currentPage = 0;

self.pageC.numberOfPages = 5;

//指定页码颜色

self.pageC.currentPageIndicatorTintColor = [UIColor redColor];

self.pageC.pageIndicatorTintColor = [UIColor greenColor];

[self.view addSubview:self.pageC];

self.arrPage = [NSMutableArray arrayWithCapacity:10];

for (int i = 1; i < 6; i++)

{

UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i]];

[self.arrPage addObject:image];

}

self.firstImage = [[UIImageView alloc] init];

self.secondImage = [[UIImageView alloc] init];

self.threeImage = [[UIImageView alloc] init];

self.currentPage = 0;

[self relodeImage];

}

-(void)relodeImage

{

if (self.currentPage == 0)

{

self.firstImage.image = [self.arrPage lastObject];

self.secondImage.image = [self.arrPage objectAtIndex:self.currentPage];

self.threeImage.image = [self.arrPage objectAtIndex:self.currentPage + 1];

}

else if (self.currentPage == self.arrPage.count - 1)

{

self.firstImage.image = [self.arrPage objectAtIndex:self.currentPage - 1];

self.secondImage.image = [self.arrPage objectAtIndex:self.currentPage];

self.threeImage.image = [self.arrPage objectAtIndex:0];

}

else

{

self.firstImage.image = [self.arrPage objectAtIndex:self.currentPage - 1];

self.secondImage.image = [self.arrPage objectAtIndex:self.currentPage];

self.threeImage.image = [self.arrPage objectAtIndex:self.currentPage + 1];

}

self.firstImage.frame = CGRectMake(0, 0, WIDTH, HEIGHT);

self.secondImage.frame = CGRectMake(WIDTH, 0, WIDTH, HEIGHT);

self.threeImage.frame = CGRectMake(WIDTH * 2, 0, WIDTH, HEIGHT);

[self.myScorolV addSubview:self.firstImage];

[self.myScorolV addSubview:self.secondImage];

[self.myScorolV addSubview:self.threeImage];

self.myScorolV.contentOffset = CGPointMake(WIDTH, 0);

}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

int number = (int)self.myScorolV.contentOffset.x;

if (number < 0 || number == 0)

{

if (self.currentPage == 0)

{

self.currentPage = (int)(self.arrPage.count - 1);

}

else

{

self.currentPage--;

}

}

else if (number > WIDTH * 2 || number == WIDTH * 2)

{

if (self.currentPage == (int)self.arrPage.count - 1)

{

self.currentPage = 0;

}

else

{

self.currentPage++;

}

}

self.pageC.currentPage = self.currentPage;

[self relodeImage];

}

改良UIScrollView滚动视图的更多相关文章

  1. UIScrollView 滚动视图—IOS开发

    转自:http://blog.csdn.net/iukey/article/details/7319314 UIScrollView 类负责所有基于 UIKit 的滚动操作. 一.创建 CGRect  ...

  2. UIScrollView滚动视图

    一.基本知识 1.初始化 UIScrollView #import "ViewController.h" #define WIDTH[[UIScreen mainScreen]bo ...

  3. OCUI界面设计:滚动视图与分页控件初探

    滚动视图(UIScrollView) 简单介绍 1.UIScrollView滚动视图能够排列并显示超出自身显示范围的内容. 2.UIScrollView内部整合了多种手势来达到丰富的界面展示效果. 3 ...

  4. [转]IOS 学习笔记(8) 滚动视图(UIScrollView)的使用方法

    下面介绍pageControl结合ScrollView实现连续滑动翻页的效果,ScrollView我们在应用开发中经常用到,以g这种翻页效果还是很好看的,如下图所示: 通过这个例子,我们重点学习UIS ...

  5. Swift - 滚动视图(UIScrollView)的用法

    1,当图片尺寸超过屏幕时,使用UIScrollView可以实现滚动条视图,即手指触摸滚动屏幕方便浏览整个页面. 1 2 3 4 5 6 var scrollView=UIScrollView() sc ...

  6. UIScrollView(滚动视图)

    (1)常用属性: 1)@property(nonatomic)CGPointcontentOffset; 这个属性⽤用来表⽰示UIScrollView滚动的位置 2)@property(nonatom ...

  7. iOS学习笔记——滚动视图(scrollView)

    滚动视图:在根视图中添加UIScrollViewDelegate协议,声明一些对象属性 @interface BoViewController : UIViewController<UIScro ...

  8. iOS关于菜单滚动视图实现

    菜单滚动视图也是在项目开发过程中比较常用到的功能,先直接看效果图 实现的效果如下: 当菜单个数的总长度超过一个屏宽度就计算每一个的文字宽度,若没有则只进行一个屏平分,点击菜单项时,滚动的视图位置会随着 ...

  9. swift:创建滚动视图的图片轮播器

    用swift创建图片轮播器和用OC创建的方式是一样的,都主要用到UIScrollView和UIImageview这两个控件,有几张图片,就将滚动视图的内容区域大小设置为每一张图片的大小乘以张数即可.然 ...

随机推荐

  1. Matches Puzzle Game

    Matches Puzzle Game 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5456 数位DP 首先我把C-A=B改为A+B=C(我觉得会简单 ...

  2. linux下串口通信与管理

    linux下的串口与windows有一些区别,下面将介绍一下linux下串口通信管理 查看是否支持USB串口: #lsmod | grep usbserial 如果没有信息:sudo apt-get ...

  3. 第二节windows系统下Xshell 5软件远程访问虚拟机 Linux系统

    下载Xshell 5软件在windows下安装 安装好后Xshell 5启动软件 下一步,检查虚拟机,配置是否正确 下一步,设置网络,保障虚拟机系统能够连接网络 下一步,进入虚拟机系统,检查虚拟机网络 ...

  4. struts2防止重复提交的标签

    struts2 token 使用说明 --------------------------------------------------------------------------------- ...

  5. 设计模式 单例模式(Singleton) [ 转载 ]

    设计模式 单例模式(Singleton) [ 转载 ] 转载请注明出处:http://cantellow.iteye.com/blog/838473 前言 懒汉:调用时才创建对象 饿汉:类初始化时就创 ...

  6. 自己写deque

    //deque /* what is a deque? In Chinese, it's called "双端队列". It's different from a queue. I ...

  7. CABasicAnimation 几种停止的回调

    一.编写一个简单的动画,使一个UIview从屏幕的左上角移动到左下角,间隔时间3S // // ViewController.m // CAAnimationTest // // Created by ...

  8. Rational Rose 2003 逆向工程转换C++ / VC++ 6.0源代码成UML类图

    目录 1.安装&破解Rational Rose 2003 1.1 安装Rose 2003 1.2 破解Rose 2003 1.3运行出错“没有找到suite objects.dl” 2. Ra ...

  9. NOIP2002-普及组复赛-第三题-选数

    题目描述 Description 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和.例如当 n=4,k=3,4 个整 ...

  10. MySQL5.6新特性Index conditontion pushdow

    index condition pushdown是MySQL5.6的新特性,主要是对MySQL索引使用的优化. Index condition push简称ICP,索引条件下推,将索引条件从serve ...