代码:

#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. mysql通过查看跟踪日志跟踪执行的sql语句

    在SQL SERVER下跟踪sql采用事件探查器,而在mysql下如何跟踪sql呢? 其实方法很简单,开启mysql的日志log功能,通过查看跟踪日志即可. 开启mysql的日志log方法: wind ...

  2. css3 -&gt; 多栏布局

    在进行多栏布局时.使用bootstrap的栅格系统能够非常轻松的实现效果,事实上css3本身也提供了多兰布局的功能. 比方,我们在一个section标签内填充了非常多内容.同一时候希望内容可以显示成三 ...

  3. leetcode 题解 || Swap Nodes in Pairs 问题

    problem: Given a linked list, swap every two adjacent nodes and return its head. For example, Given ...

  4. QT开发pjsip的VOIP,A8平台运行

    QT开发pjsip的VOIP 开发环境 平台:A8 环境:Linux-3.0.8 实现功能:使用QT开发VOIP进行初始化.拨号.挂起 测试工具:minisipserver服务器 效果 界面: min ...

  5. android开发之自定义AutoCompleteTextView

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

  6. 能发送http请求(get,post)的工具

    能发送http请求(get,post)的工具, 1.  fiddler 前端自己模拟发送请求 2.  其他 链接:https://www.zhihu.com/question/20367546/ans ...

  7. 自己做的demo---关于java控制台输入跟类型转化跟处理异常的demo

    package exception; import java.util.InputMismatchException; import java.util.Scanner; /*public class ...

  8. (转) Spring读书笔记-----部署我的第一个Spring项目

    一.Spring介绍 Spring是一个轻量级的Java EE容器,它也是一种从实际需求出发,着眼于轻便,灵活,易于开发,易测试和易部署的轻量级开发框架.Spring它完成了大量开发中的通用步骤,留给 ...

  9. Spring中事务的5种属性总结

    Sping的事务 和 数据库的事务是不同的概念,数据库的事务一般称为底层事务 Spring的事务是对这种事务的抽象 我称之为逻辑事务 Spring对事务的功能进行了扩展,除了基本的Isolation之 ...

  10. win7下配置apache和php

    1.软件装备 PHP:http://php.net/downloads.php non-thread-safe是非安全线程主要与IIS搭配环境. thread-safe安全线程与Apache搭配环境. ...