//初始化当前视图
_currentImageView = [[UIImageView alloc] init];
[_currentImageView setImageWithURL:[NSURL URLWithString:[array_pic objectAtIndex:]]];
_currentImageView.frame = CGRectMake(myScroller.frame.size.width, , myScroller.frame.size.width,);
// _currentImageView.contentMode = UIViewContentModeScaleAspectFill;
[myScroller addSubview:_currentImageView]; _nextImageView = [[UIImageView alloc] init];
[_nextImageView setImageWithURL:[NSURL URLWithString:[array_pic objectAtIndex:]]];
_nextImageView.frame = CGRectMake(myScroller.frame.size.width * , , myScroller.frame.size.width,);
// _nextImageView.contentMode = UIViewContentModeScaleAspectFill;
[myScroller addSubview:_nextImageView]; //初始化上一个视图
_previousView = [[UIImageView alloc] init];
[_previousView setImageWithURL:[NSURL URLWithString:[array_pic objectAtIndex:]]];
_previousView.frame = CGRectMake(, ,myScroller.frame.size.width,);
// _previousView.contentMode = UIViewContentModeScaleAspectFill; [myScroller addSubview:_previousView]; } {
SMPageControl *pageControl = [[SMPageControl alloc] init];
[pageControl setFrame:CGRectMake(, myScroller.frame.size.height+ - 10.0f,myScroller.frame.size.width,10.0f)];
[pageControl setNumberOfPages:];
[pageControl setBackgroundColor:[UIColor clearColor]];
[pageControl setCurrentPage:];
[pageControl setCurrentPageIndicatorTintColor:[UIColor lightGrayColor]];
[pageControl setPageIndicatorTintColor:[UIColor grayColor]];
myPageControl=pageControl;
[self.view addSubview:myPageControl];
} if (![myTimer isValid]) {
myTimer=[NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(updateAuto) userInfo:nil repeats:YES];
} #pragma mark 时钟动画调用方法
- (void)updateAuto
{
if (_isDraging) {
return;
} CGPoint offset = myScroller.contentOffset; offset.x += self.view.frame.size.width;
if (offset.x > self.view.frame.size.width*) {
offset.x = self.view.frame.size.width;
} [myScroller setContentOffset:offset animated:YES];
} #pragma mark - 代理方法
#pragma mark 准备开始拖动
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
_isDraging = YES;
} #pragma mark 视图停止滚动
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
_isDraging = NO;
} #pragma mark 已经拖动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ static int i = ;//当前展示的是第几张图片 float offset = scrollView.contentOffset.x;
if (_nextImageView.image == nil || _previousView.image == nil) { //加载下一个视图
[_nextImageView setImageWithURL:[NSURL URLWithString:[array_pic objectAtIndex:i == kCount ? : i+]]]; //加载上一个视图
[_previousView setImageWithURL:[NSURL URLWithString:[array_pic objectAtIndex:i == ? kCount : i - ]]];
} if (offset == ) {
_currentImageView.image = _previousView.image;
scrollView.contentOffset = CGPointMake(scrollView.bounds.size.width, );
_previousView.image = nil; if (i == ) {
i = kCount;
}else{
i -= ;
} } if (offset == scrollView.bounds.size.width * ) {
_currentImageView.image = _nextImageView.image;
scrollView.contentOffset = CGPointMake(scrollView.bounds.size.width, );
_nextImageView.image = nil; if (i == kCount) {
i = ; //如果当前图片索引在最后一个,则重置为0,否则+1
}else{
i += ;
}
}
[myPageControl setCurrentPage:i];
}

iOS 有关自动轮播图片的更多相关文章

  1. JavaScript学习之自动轮播图片

    定时器 在实现轮播图之前需要首先了解一下JavaScript的定时器 setInterval()和clearInterval() 1.setInterval() 方法可按照指定的周期(以毫秒计)来调用 ...

  2. jQuery实际案例①——淘宝精品广告(鼠标触碰切换图片、自动轮播图片)

    遇到的问题:自动轮播的实现,实质与轮播图一样儿一样儿的,不要被不同的外表所欺骗,具体的js代码如下:

  3. js自动轮播图片的两种循环方法(原创)

    用5个div,布局从左到右5张图片,从左到右5个div分别指定ID为img1,img2,img3,img4,img5.(背景是relative,5个div是相对于背景absolute定位) 显示如下: ...

  4. jQuery自动轮播图片焦点图

    在线演示 本地下载

  5. 解决:使用 swiper 自动轮播图片,当拖动过 swiper 内的内容时,导致不继续自动轮播

    版本为1.3 当使用了 swiper 后: var mySwiper = new Swiper('.banner .swiper-container', { autoplay: 3000, loop: ...

  6. 仿网易新闻 ViewPager 实现图片自动轮播

    新闻 App 首页最上方一般会循环播放热点图片,如下图所示. 本文主要介绍了利用 ViewPager 实现轮播图片,图片下方加上小圆点指示器标记当前位置,并利用 Timer+Handler 实现了自动 ...

  7. iOS开发笔记6:图片轮播及其无限循环效果

    平时APP中的广告位或者滚动的新闻图片等用到的就是图片轮播这种效果,实现方式主要有两种,一种是ScrollView+ImageView,另一种则是通过CollectionView,今天总结的是Scro ...

  8. ios - 图片自动轮播定时器(NSTimer)以及消息循环模式简介

    本文只是演示如何设置图片轮播的定时器. 创建全局变量NSTimer 程序启动后就开始轮播图片,所以在- (void)viewDidLoad中就启动定时器. 将定时器放入消息循环池中.- (void)v ...

  9. AJ学IOS(11)UI之图片自动轮播

    AJ分享,必须精品 先看效果 代码 #import "NYViewController.h" #define kImageCount 5 @interface NYViewCont ...

随机推荐

  1. 如何在给快满的Linux分区"无伤"扩容

    1. 首先在虚拟机设置里面设置磁盘的扩展,前提条件是该虚拟机没有快照. 2. 在虚拟机设置好以后,需要开机在系统里扩容磁盘 3. 使用 # fdisk /dev/sda 扩展磁盘,具体操作使用 m 选 ...

  2. Android开发之实用小知识点汇总-2

    1.EditText 中将光标移到文字末尾: EditText mEdit = (EditText)this.findViewById(R.id.EditText01); mEdit .setText ...

  3. ubuntu查看命令

    以非root用户更新系统 sudo: sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等.这样不仅减少了root用 ...

  4. lnmp 安装环境之后discuz论坛排版乱的问题

    服务器系统类型:centos 6.5 环境:使用lnmp官方安装shell安装 (http://lnmp.org/install.html) 在部署dz之后,访问页面 出现排版乱,资源不能加载的问题: ...

  5. [转]vs2010 快捷键大全

    vs2010 快捷键大全 VS2010版快捷键 Ctrl+E,D ----格式化全部代码  Ctrl+E,F ----格式化选中的代码  CTRL + SHIFT + B生成解决方案  CTRL + ...

  6. eclipse中相同代码的高亮显示

    在eclipse中 当选中一串字符时,让其他相同字符代码都高亮显示,操作如下: windows-> preferences-> java-> Editor-> Mark Occ ...

  7. 对 Azure 虚拟网络网关的改进

    YU-SHUN WANG Azure 网络高级项目经理 在 2014 年欧洲 TechEd 大会上,我们宣布了对Azure 虚拟网络网关的多项改进: 1.  高性能网关 SKU 2.  Azure 虚 ...

  8. 【原创】深度神经网络(Deep Neural Network, DNN)

    线性模型通过特征间的现行组合来表达“结果-特征集合”之间的对应关系.由于线性模型的表达能力有限,在实践中,只能通过增加“特征计算”的复杂度来优化模型.比如,在广告CTR预估应用中,除了“标题长度.描述 ...

  9. 【转】蓝牙ble app开发(三) -- 抓包

    原文网址:http://blog.csdn.net/lckj686/article/details/43156617 关于android 蓝牙app开发抓包的重要性在 android 蓝牙ble ap ...

  10. memcache 存储单个KEY,数据量过大的时候性能慢!以及简单的memcache不适合用到的场景

    今天有人问到我:memcache存储大数据量,10K,100K,1M的时候,效果怎么样??我回答:不好,效果非常慢.对方问:为什么啊??我回答不上来...于是就找了点资料. memcached使用需要 ...