//创建ScrollView的方法

-(void)createScrollView

{

UIScrollView *sv = [[UIScrollView alloc]initWithFrame:CGRectMake(5, 5, self.view.frame.size.width - 10, self.view.frame.size.height-10)];

//w代表sv.frame的宽度

CGFloat w = self.view.frame.size.width - 10;

//滑动的size的设置

//宽度 如果要横着滑动设置大于sv.frame的宽度

sv.contentSize = CGSizeMake(3*w, sv.frame.size.height-10);

//获得三个图放到UIImageView

for (int i =0; i<3; i++)

{

//获得三张图

UIImage*image =[UIImage imageNamed:[NSString stringWithFormat:@"43_%d.jpg",i+1]];

//三张图放到imageView上去

UIImageView *iv = [[UIImageView alloc]initWithImage:image];

//设定imageView的位置

iv.frame = CGRectMake(i*w, 0, w, self.view.frame.size.height-10);

//        iv.userInteractionEnabled = YES;

//iv放到父视图 ScrollView上面去

[sv addSubview:iv];

}

//水平滑动指示条

sv.showsHorizontalScrollIndicator = NO;

//垂直滑动指示条

sv.showsVerticalScrollIndicator = NO;

//设置按页滑动 page

//  sv.pagingEnabled = YES;

//弹性设置

sv.bounces = NO;

sv.userInteractionEnabled = YES;

//自带放大 缩小 option

//默认不自己放大缩小

//设置放大最大的倍数

sv.maximumZoomScale = 2;

//设置最小缩小到多大

sv.minimumZoomScale = 0.5;

//设置代理

sv.delegate = self;

//要不要返回顶部

sv.scrollsToTop = YES;

//添加背景色

sv.backgroundColor = [UIColor redColor];

//添加到主界面

[self.view addSubview:sv];

//

UIPageControl *pageC = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 0, 200, 40)];

pageC.center=CGPointMake(150,300);

pageC.numberOfPages = 10;

pageC.currentPage =2;

pageC.tag = 200;

pageC.currentPageIndicatorTintColor = [UIColor greenColor];

[pageC addTarget:self action:@selector(pageC:) forControlEvents:UIControlEventValueChanged];

pageC.pageIndicatorTintColor = [UIColor blackColor];

pageC.backgroundColor = [UIColor redColor];

[self.view addSubview:pageC];

}

#pragma mark -delegate

//控制放缩 代理方法

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

{

//使得所有的界面都可以进行放缩

return scrollView.subviews[0];

}

//已经滑动

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

NSLog(@"开始滑动之后 执行的方法");

NSInteger index = scrollView.contentOffset.x /scrollView.frame.size.width;

UIPageControl *pc =(UIPageControl*) [self.view viewWithTag:200];

pc.currentPage =index;

}

//已经放缩

- (void)scrollViewDidZoom:(UIScrollView *)scrollView

{

NSLog(@"放缩之后 执行的方法");

}

//开始拖动的方法

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

{

NSLog(@"即将滑动的状态 指头轻轻一划");

}

// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset

{

//scrollview就是当前的scrollview

//velocity加速度

//offset 移动

NSLog(@"即将结束滑动,手指移开 惯性还在滑的时候");

}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate

{

NSLog(@"已经结束滑动");

}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

{

NSLog(@"减速");

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

NSLog(@"减速完成 和滑动结束 状态基本一致");

}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

{

NSLog(@"结束滑动的动画");

}

//- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;     // return a view that will be scaled. if delegate returns nil, nothing happens

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view

{

//

bigSmallV = view;

NSLog(@"即将开始缩放");

}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale

{

NSLog(@"已经结束缩放");

}

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView

{

NSLog(@"返回是否可以滑动到顶部");

//返回YES表示可以滑动到顶部 返回No表示不可以滑动到顶部

return YES;

}

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView

{

NSLog(@"已经返回到顶部");

}

#pragma mark - delegate

-(void)pageC:(UIPageControl *)pc

{

}

iosUIScrollView以及UIPageControl的基本使用以及所有代理方法的更多相关文章

  1. iOS- UIScrollView、UIPageControl分页浏览图片

    1.先介绍下UIScrollView的常见属性 @property(nonatomic) CGPoint contentOffset; // 记录UIScrollView滚动的位置 @property ...

  2. iOS-UIScrollView和UIPageControl的综合实力,滚动图,轮播图

    本代码主要实现图片之间的切换 目录结构 代码 ViewController.m文件 #import "ViewController.h" @interface ViewContro ...

  3. iOS--UIScrollView基本用法和代理方法

    主要是为了记录下UIScrollView的代理方法吧 在帮信息学院的学长做东西的时候需要大量用到分块浏览,所以就涉及到很多的关于scrollview,所以也就有了这篇文章   - (void)view ...

  4. UIPageControl简单使用

    1.添加一个UIPageControl到view中 -(void)addPageControl { UIPageControl* page=[[UIPageControl alloc]init]; p ...

  5. UI:UIScrollView、UIPageControl

    一.UIScrollView的常⽤用属性 二.UIScrollView的常⽤用代理方法 三.UIPageControl的使⽤用 四.UIPageControl与UIScrollView的结合使⽤用 U ...

  6. IOS-UIScrollView实现图片分页

    1.设置可以分页 _scrollView.pagingEnabled = YES; 2.添加PageControl UIPageControl *pageControl = [[UIPageContr ...

  7. 使用UIPageControl UIScrollView制作APP引导界面

    1. 新建两个视图控制器类(继承自UIViewController), 在AppDelegate.m中指定根视图控制器 #import "AppDelegate.h" #impor ...

  8. 利用UIScrollView和UIPageControl实现多页图片欢迎页面

    在.h文件当中实现UIScrollViewDelegate协议,让控制器充当代理: #import <UIKit/UIKit.h> @interface RPRootViewControl ...

  9. UIScrollView 和 UIPageControl

    UIScrollView [滚动视图]非常重要 UIScrollView是滚动视图,是其它带有滚动功能视图的父类, 本身不显示或者只显示背景,主要负责子视图的滚动和翻页. 一.常用属性 1.基本方法 ...

随机推荐

  1. Ubuntu 忘记密码

    1重启电脑Shift键进入GRUB引导模式如下图所示,选择第二行的recovery mode. 2 安e进入recovery mode 编译kernel进行启动参数 3 在linux /boot/vm ...

  2. 关于Windows Boot Manager、Bootmgfw.efi、Bootx64.efi、bcdboot.exe 的详解

    1. http://bbs.wuyou.com/forum.php?mod=viewthread&tid=303679&fromuid=396698

  3. JavaScript Date对象更进一步

    总结分享这个近期开发解决的一个Bug. Javascript的Date对象具有容错性,会自动根据当年的日期根据设置的属性值转换,也就是说Date对象的setDate会影响setMonth,month会 ...

  4. FileZilla客户端源码解析

    FileZilla客户端源码解析 FTP是TCP/IP协议组的协议,有指令通路和数据通路两条通道.一般来说,FTP标准命令TCP端口号是21,Port方式数据传输端口是20. FileZilla作为p ...

  5. C#动态编程

    class Program { static void Main(string[] args) { Test(); } public static void Test() { //声明代码的部分 Co ...

  6. jquery选择器之基本筛选选择

    1.基本选择器 2.内容筛选选择器 3.可见性筛选选择器 4.属性筛选选择器 5.子元素筛选选择器 6.表单元素选择器 7.表单对象属性筛选器

  7. C# WebBrowser禁止F5刷新

    在用写一个桌面软件的过程中,用到webbrowser实现界面.这时有一个禁止webbrowser通过f5按键进行刷新的要求.本着边做边学的原则,本菜查了一下百度,原来这么简单,代码如下: this.w ...

  8. logstash 输出到elasticsearch 自动建立index

    由于es 单index 所能承受的数据量有限,之前情况是到400w数据300G左右的时候,整个数据的插入会变得特别慢(索引重建)甚至会导致集群之间的通信断开,于是我们采用每天一个index的方法来缓解 ...

  9. 【转】Python BeautifulSoup 中文乱码解决方法

    这篇文章主要介绍了Python BeautifulSoup中文乱码问题的2种解决方法,需要的朋友可以参考下 解决方法一: 使用python的BeautifulSoup来抓取网页然后输出网页标题,但是输 ...

  10. 第七十三节,css盒模型

    css盒模型 学习要点: 1.元素尺寸 2.元素内边距 3.元素外边距 4.处理溢出 本章主要探讨HTML5中CSS盒模型,学习怎样了解元素的外观配置以及文档的整体布局. 一.元素尺寸 CSS盒模型中 ...