代码:

#import "RootViewController.h"

@implementation RootViewController
@synthesize scrollView; - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. int pageCount = ;
scrollView = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[self.view addSubview:scrollView]; scrollView.backgroundColor = [UIColor redColor];
scrollView.scrollEnabled = NO;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * pageCount, scrollView.frame.size.height);
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.delegate = self; CGRect rect = [[UIScreen mainScreen]bounds];
NSArray *colors = [NSArray arrayWithObjects:[UIColor yellowColor], [UIColor blueColor], [UIColor purpleColor], nil]; for (int i = ; i < pageCount; i++) { CGRect aRect = CGRectMake(rect.origin.x + (i * rect.size.width), rect.origin.y,
rect.size.width, rect.size.height);
UIView *view1 = [[UIView alloc]initWithFrame:aRect];
view1.backgroundColor = colors[i];
[scrollView addSubview:view1];
} [self moveToPage:];
} - (void) moveToPage:(int)index
{
index--;
CGRect rect = [[UIScreen mainScreen]bounds];
CGPoint point = CGPointMake(rect.size.width * index, );
[scrollView setContentOffset:point];
} - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
// 拖拽完毕以后调用
int index = [self getPageIndex:scrollView];
NSLog(@"index = %d",index);
} -(int) getPageIndex:(UIScrollView *)scrollView
{
return fabs(scrollView.contentOffset.x) / scrollView.frame.size.width;
} @end

scrollview 例子2的更多相关文章

  1. React Native之 ScrollView介绍和使用

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  2. 关于ScrollView嵌套ListView问题

    Android开发之ScrollView中嵌套ListView的解决方案   原文:http://blog.csdn.net/minimicall/article/details/40983331   ...

  3. ScrollView控件实现屏幕滚动

    滚动视图是指当拥有很多内容,屏幕显示不完全时,需要通过滚动来显示完整的视图 ScrollView的种类: (1)水平滚动视图:HorizontalScrollView (2)垂直滚动视图:Scroll ...

  4. SwipeRefreshLayout嵌套ScrollView包裹复杂头布局和RecyclerView

    布局如下:上面是一个描述有:头像和部分信息的布局,底部是一个RecyclerView: 想法:想实现RecyclerView向上滚动的时候,隐藏上面的头像布局信息:使用了 CoordinatorLay ...

  5. Android ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法

    例子,在ScrollView下加入的组件,无论如何也不能自动扩展到屏幕高度. 布局文件. [html] <?xml version="1.0" encoding=" ...

  6. iOS开发——项目篇—高仿百思不得姐 05——发布界面、发表文字界面、重识 bounds、frame、scrollView

    加号界面(发布模块) 一.点击加号modal出发布模块,创建控件,布局控件1)使用xib加载view,如果在viewDidLoad创建控件并设置frame 那么self.view 的宽高 拿到的是xi ...

  7. 四种方案解决ScrollView嵌套ListView问题(转)

    以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollVie ...

  8. 在ScrollView下加入的组件,不能自动扩展到屏幕高度

    ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法 在ScrollView中添加一个android:fillV ...

  9. NGUI ScrollView总结

    1顶级父类加boxCollider和UIDragScrollView脚本保证在item拖走后也能通过拖拽剩余区域的方式操作. 2下一级添加UIPanel在Clipping设定区域,注意如果设定soft ...

随机推荐

  1. C#基础知识—父类和子类的关系

    基础知识一: using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms ...

  2. Android NDK 【错误】The method loadLibrary(String) is undefined for the type Settings.Syste

    [错误]The method loadLibrary(String) is undefined for the type Settings.System [解决方法] 不要加入包import andr ...

  3. vxworks

    VxWorks 是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统.Tornado 是WRS 公司推出的一套实时操作系统开发环境,类似Mi ...

  4. Apache CXF 3.0: CDI 1.1 Support as Alternative to Spring--reference

    With Apache CXF 3.0 just being released a couple of weeks ago, the project makes yet another importa ...

  5. 纯IPv6环境App适配的坑

    来源:伯乐在线专栏作者 - MrPeak 链接:http://ios.jobbole.com/86580/ 苹果从2016年6月1号开始,强制所有app必须支持纯IPv6的网络环境.这项举措将对IPv ...

  6. android开发之自定义AutoCompleteTextView

    AutoCompleteTextView,很多人都用过,有些情况下使用Google提供的ArrayAdapter作为适配器就可以完成需求,但是在实际开发中,我们经常需要开发自定义适配器来完成开发工作. ...

  7. css修改li前面的小圆点的颜色

    直接改 li 的style 的 color 就好:就是这样:over

  8. ajax 基础教程

    这是一本什么书?这是一本技术类的书籍,主要从历史.XMLHttpRequest对象.怎么样于服务器交互.构建完备的Ajax开发工具箱.使用jsUnit测试javascript 代码,总之就是让我们从这 ...

  9. 19个非常有用的Javascript类库

    Blackbird是一款非常酷的JavaScript调试工具,带有一个漂亮的界面显示和过滤调试信息. http://www.gscottolson.com/blackbirdjs/ Treesaver ...

  10. Java中OutOfMemoryError(内存溢出)的情况及解决办法

    java.lang.OutOfMemoryError: Java heap space // TODO Auto-generated method stub Vector v = new Vector ...