1. //
  2. // ViewController.m
  3. // Ocproject
  4. //
  5. // Created by wenzhe yi on 2018/2/28.
  6. // Copyright © 2018年 wenzhe yi. All rights reserved.
  7. //
  8.  
  9. #import "Shuanghui.h"
  10. #import "ViewController.h"
  11.  
  12. #define imageCount 5
  13.  
  14. #define kscrollviewsize (_scrollView.frame.size)
  15.  
  16. @interface ViewController()<UIScrollViewDelegate>
  17.  
  18. @property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
  19. @property (weak, nonatomic) IBOutlet UIPageControl *pageController;
  20.  
  21. @property(strong,nonatomic) NSTimer *timer;
  22.  
  23. @end
  24.  
  25. @implementation ViewController
  26.  
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view, typically from a nib.
  30.  
  31. [self initUi];
  32.  
  33. [self initPageController];
  34. [self initTimer];
  35.  
  36. }
  37.  
  38. -(void)initTimer{
  39. _timer = [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(autoBanner) userInfo:nil repeats:YES];
  40. }
  41. -(void)initUi{
  42. [self initScrollView];
  43.  
  44. }
  45.  
  46. //开始拖拽的时候计时器停止
  47. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  48. [_timer invalidate];
  49. }
  50.  
  51. //拖拽结束的时候在开启定时器
  52. -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
  53. [self initTimer];
  54. }
  55. -(void)initPageController{
  56. _pageController.numberOfPages=imageCount;
  57.  
  58. //非选中颜色
  59. _pageController.pageIndicatorTintColor=[UIColor grayColor];
  60.  
  61. //选中的颜色
  62. _pageController.currentPageIndicatorTintColor=[UIColor redColor];
  63.  
  64. //当前页
  65. _pageController.currentPage=;
  66. }
  67. -(void)initScrollView{
  68. // UIImageView *iv = [[UIImageView alloc]initWithFrame:_scrollView.bounds];
  69. //
  70. // //设图片
  71. // iv.image=[UIImage imageNamed:@"img_01"];
  72. //
  73. // //添加
  74. // [_scrollView addSubview:iv];
  75.  
  76. // CGSize scrollViewSize=_scrollView.frame.size;
  77.  
  78. for (int i=; i<imageCount; i++) {
  79.  
  80. CGFloat imageX=i*kscrollviewsize.width;
  81.  
  82. UIImageView *iv =[[UIImageView alloc] initWithFrame:CGRectMake(imageX, , kscrollviewsize.width, kscrollviewsize.height)];
  83.  
  84. //imagepath string
  85. NSString *path=[NSString stringWithFormat:@"img_%02d",i+];
  86.  
  87. //设置pic
  88. iv.image=[UIImage imageNamed:path];
  89.  
  90. //add
  91.  
  92. [_scrollView addSubview:iv];
  93. }
  94. _scrollView.contentSize=CGSizeMake(*kscrollviewsize.width, );
  95.  
  96. //隐藏滚动条
  97. _scrollView.showsHorizontalScrollIndicator=NO;
  98.  
  99. //分页效果
  100. _scrollView.pagingEnabled=YES;
  101. //代理
  102. _scrollView.delegate=self;
  103. }
  104.  
  105. - (void)didReceiveMemoryWarning {
  106. [super didReceiveMemoryWarning];
  107. // Dispose of any resources that can be recreated.
  108. }
  109.  
  110. -(void)needMoreMeet{
  111. NSLog(@"I LIST");
  112. }
  113. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  114.  
  115. }
  116. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  117.  
  118. _pageController.currentPage=scrollView.contentOffset.x/kscrollviewsize.width;
  119.  
  120. }
  121.  
  122. //无线循环轮播点击事件
  123. - (IBAction)move:(id)sender {
  124. [self autoBanner];
  125. }
  126.  
  127. -(void)autoBanner{
  128. CGPoint offset=_scrollView.contentOffset;
  129.  
  130. NSInteger currentPage = _pageController.currentPage;
  131.  
  132. if(currentPage==imageCount-){
  133. currentPage=;
  134. offset=CGPointZero;
  135.  
  136. }else{
  137. currentPage+=;
  138. offset.x+=kscrollviewsize.width;
  139. }
  140.  
  141. _pageController.currentPage=currentPage;
  142. [_scrollView setContentOffset:offset animated:YES];
  143.  
  144. }
  145.  
  146. @end

ios轮播的更多相关文章

  1. 一步一步拆解一个简单的iOS轮播图(三图)

    导言(可以不看): 不吹不黑,也许是东半球最简单的iOS轮播图拆分注释(讲解不敢当)了(tree new bee).(一句话包含两个人,你能猜到有谁吗?提示:一个在卖手机,一个最近在卖书)哈哈... ...

  2. iOS -- 轮播图

    UIScrollView + 多张 ImageView 实现轮播 实现原理: 将所有图片的名字储存在数组 imageAry 中,imageAry 的元素个数为 num,在 scrollView 上添加 ...

  3. IOS轮播图

    轮播图播放的主要技术在于: cell的封装.这里采用UICollectionViewCell实现. #import <UIKit/UIKit.h> @interface CircleVie ...

  4. iOS 轮播中遇到的问题(暂停、重新启动)

    一. 轮播的优化或者用Collection来实现 二.Timer  问题 我们可以这样来使用一个Timer [NSTimer scheduledTimerWithTimeInterval:1.0 ta ...

  5. ios轮播图片用法

    // // ZQRViewController.m // 04-图片轮播器 // // Created by apple on 17-08-24. // Copyright (c) 2017年 zzq ...

  6. iOS:实现图片的无限轮播(二)---之使用第三方库SDCycleScrollView

    iOS:实现图片的无限轮播(二)---之使用第三方库SDCycleScrollView 时间:2016-01-19 19:13:43      阅读:630      评论:0      收藏:0   ...

  7. iOS开发之ImageView复用实现图片无限轮播

    在上篇博客中iOS开发之多图片无缝滚动组件封装与使用给出了图片无限轮播的实现方案之一,下面在给出另一种解决方案.今天博客中要说的就是在ScrollView上贴两个ImageView, 把ImageVi ...

  8. ReactNative新手学习之路04 组件化开发轮播图swiper支持安卓和IOS

    react native 新手之路04 组件化开发轮播图swiper支持安卓和IOS npm install react-native-carousel --save git 地址Properties ...

  9. iOS 图片轮播图(自动滚动)

    iOS 图片轮播图(自动滚动) #import "DDViewController.h" #define DDImageCount 5 @interface DDViewContr ...

随机推荐

  1. solidity合约详解

    Solidity 是一个面向合约的高级语言,其语法类似于JavaScript .是运行在以太坊虚拟机中的代码.这里我们用的是remix编译环境.是一个在线的编译环境.地址为http://remix.e ...

  2. [leetcode-666-Path Sum IV]

    If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digit ...

  3. 【转】cpu的核心数与线程数的关系

    原文地址:http://www.dn580.com/dnzs/dncs/2013/10/08/172948914.html 我们在选购电脑的时候,CPU是一个需要考虑到核心因素,因为它决定了电脑的性能 ...

  4. 欢迎来怼——第14次Scrum会议(10/26)

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/26  17:00~17:13(总计13min).地点:计 ...

  5. C语言 内存分配 地址 指针 数组 参数 实例解析

    . Android源码看的鸭梨大啊, 补一下C语言基础 ... . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/detai ...

  6. LintCode-532.逆序对

    逆序对 在数组中的两个数字如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.给你一个数组,求出这个数组中逆序对的总数. 概括:如果a[i] > a[j] 且 i < j, a[i ...

  7. alpha阶段个人总结(201521123031林庭亦)

    一.个人总结 第一部分:硬的问题 第二部分:软的问题,在成长路上学到了什么? 1 当你看到不靠谱的设计.糟糕的代码.过时的文档和测试用例的时候,不要想 "既然别人的代码已经这样了,我的代码也 ...

  8. Qt代码覆盖率code coverage(VS版)

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt代码覆盖率code coverage(VS版)     本文地址:http://techi ...

  9. oracle 11g ADG实施手册(亲测,已成功部署多次)

    一:实验环境介绍 虚拟机系统:    RHEL Linux 6.4(64位) 数据库版本:    Oracle 11gR2 11.2.0.4 (64位) IP地址规划: 主数据库 192.168.11 ...

  10. 网络编程--System.Net

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...