ios轮播
- //
- // ViewController.m
- // Ocproject
- //
- // Created by wenzhe yi on 2018/2/28.
- // Copyright © 2018年 wenzhe yi. All rights reserved.
- //
- #import "Shuanghui.h"
- #import "ViewController.h"
- #define imageCount 5
- #define kscrollviewsize (_scrollView.frame.size)
- @interface ViewController()<UIScrollViewDelegate>
- @property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
- @property (weak, nonatomic) IBOutlet UIPageControl *pageController;
- @property(strong,nonatomic) NSTimer *timer;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- [self initUi];
- [self initPageController];
- [self initTimer];
- }
- -(void)initTimer{
- _timer = [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(autoBanner) userInfo:nil repeats:YES];
- }
- -(void)initUi{
- [self initScrollView];
- }
- //开始拖拽的时候计时器停止
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
- [_timer invalidate];
- }
- //拖拽结束的时候在开启定时器
- -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
- [self initTimer];
- }
- -(void)initPageController{
- _pageController.numberOfPages=imageCount;
- //非选中颜色
- _pageController.pageIndicatorTintColor=[UIColor grayColor];
- //选中的颜色
- _pageController.currentPageIndicatorTintColor=[UIColor redColor];
- //当前页
- _pageController.currentPage=;
- }
- -(void)initScrollView{
- // UIImageView *iv = [[UIImageView alloc]initWithFrame:_scrollView.bounds];
- //
- // //设图片
- // iv.image=[UIImage imageNamed:@"img_01"];
- //
- // //添加
- // [_scrollView addSubview:iv];
- // CGSize scrollViewSize=_scrollView.frame.size;
- for (int i=; i<imageCount; i++) {
- CGFloat imageX=i*kscrollviewsize.width;
- UIImageView *iv =[[UIImageView alloc] initWithFrame:CGRectMake(imageX, , kscrollviewsize.width, kscrollviewsize.height)];
- //imagepath string
- NSString *path=[NSString stringWithFormat:@"img_%02d",i+];
- //设置pic
- iv.image=[UIImage imageNamed:path];
- //add
- [_scrollView addSubview:iv];
- }
- _scrollView.contentSize=CGSizeMake(*kscrollviewsize.width, );
- //隐藏滚动条
- _scrollView.showsHorizontalScrollIndicator=NO;
- //分页效果
- _scrollView.pagingEnabled=YES;
- //代理
- _scrollView.delegate=self;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void)needMoreMeet{
- NSLog(@"I LIST");
- }
- -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
- }
- -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
- _pageController.currentPage=scrollView.contentOffset.x/kscrollviewsize.width;
- }
- //无线循环轮播点击事件
- - (IBAction)move:(id)sender {
- [self autoBanner];
- }
- -(void)autoBanner{
- CGPoint offset=_scrollView.contentOffset;
- NSInteger currentPage = _pageController.currentPage;
- if(currentPage==imageCount-){
- currentPage=;
- offset=CGPointZero;
- }else{
- currentPage+=;
- offset.x+=kscrollviewsize.width;
- }
- _pageController.currentPage=currentPage;
- [_scrollView setContentOffset:offset animated:YES];
- }
- @end
ios轮播的更多相关文章
- 一步一步拆解一个简单的iOS轮播图(三图)
导言(可以不看): 不吹不黑,也许是东半球最简单的iOS轮播图拆分注释(讲解不敢当)了(tree new bee).(一句话包含两个人,你能猜到有谁吗?提示:一个在卖手机,一个最近在卖书)哈哈... ...
- iOS -- 轮播图
UIScrollView + 多张 ImageView 实现轮播 实现原理: 将所有图片的名字储存在数组 imageAry 中,imageAry 的元素个数为 num,在 scrollView 上添加 ...
- IOS轮播图
轮播图播放的主要技术在于: cell的封装.这里采用UICollectionViewCell实现. #import <UIKit/UIKit.h> @interface CircleVie ...
- iOS 轮播中遇到的问题(暂停、重新启动)
一. 轮播的优化或者用Collection来实现 二.Timer 问题 我们可以这样来使用一个Timer [NSTimer scheduledTimerWithTimeInterval:1.0 ta ...
- ios轮播图片用法
// // ZQRViewController.m // 04-图片轮播器 // // Created by apple on 17-08-24. // Copyright (c) 2017年 zzq ...
- iOS:实现图片的无限轮播(二)---之使用第三方库SDCycleScrollView
iOS:实现图片的无限轮播(二)---之使用第三方库SDCycleScrollView 时间:2016-01-19 19:13:43 阅读:630 评论:0 收藏:0 ...
- iOS开发之ImageView复用实现图片无限轮播
在上篇博客中iOS开发之多图片无缝滚动组件封装与使用给出了图片无限轮播的实现方案之一,下面在给出另一种解决方案.今天博客中要说的就是在ScrollView上贴两个ImageView, 把ImageVi ...
- ReactNative新手学习之路04 组件化开发轮播图swiper支持安卓和IOS
react native 新手之路04 组件化开发轮播图swiper支持安卓和IOS npm install react-native-carousel --save git 地址Properties ...
- iOS 图片轮播图(自动滚动)
iOS 图片轮播图(自动滚动) #import "DDViewController.h" #define DDImageCount 5 @interface DDViewContr ...
随机推荐
- solidity合约详解
Solidity 是一个面向合约的高级语言,其语法类似于JavaScript .是运行在以太坊虚拟机中的代码.这里我们用的是remix编译环境.是一个在线的编译环境.地址为http://remix.e ...
- [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 ...
- 【转】cpu的核心数与线程数的关系
原文地址:http://www.dn580.com/dnzs/dncs/2013/10/08/172948914.html 我们在选购电脑的时候,CPU是一个需要考虑到核心因素,因为它决定了电脑的性能 ...
- 欢迎来怼——第14次Scrum会议(10/26)
一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/26 17:00~17:13(总计13min).地点:计 ...
- C语言 内存分配 地址 指针 数组 参数 实例解析
. Android源码看的鸭梨大啊, 补一下C语言基础 ... . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/detai ...
- LintCode-532.逆序对
逆序对 在数组中的两个数字如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.给你一个数组,求出这个数组中逆序对的总数. 概括:如果a[i] > a[j] 且 i < j, a[i ...
- alpha阶段个人总结(201521123031林庭亦)
一.个人总结 第一部分:硬的问题 第二部分:软的问题,在成长路上学到了什么? 1 当你看到不靠谱的设计.糟糕的代码.过时的文档和测试用例的时候,不要想 "既然别人的代码已经这样了,我的代码也 ...
- Qt代码覆盖率code coverage(VS版)
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt代码覆盖率code coverage(VS版) 本文地址:http://techi ...
- oracle 11g ADG实施手册(亲测,已成功部署多次)
一:实验环境介绍 虚拟机系统: RHEL Linux 6.4(64位) 数据库版本: Oracle 11gR2 11.2.0.4 (64位) IP地址规划: 主数据库 192.168.11 ...
- 网络编程--System.Net
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...