代码:

#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. SampleManager(赛默飞)

  2. MVC-控制器向View传值的三种方法

    1.提供视图模型对象 你能把一个对象作为View方法的参数传递给视图. public ViewResult Index() { DateTime date = DateTime.Now; return ...

  3. 【NodeJs】Ctrl+C在Linux平台和Windows平台下的TCP连接中的不同表现

    Linux平台:CentOS release 6.5 (Final) Windows平台:Windows 7 旗舰版 服务器端代码如下: var net = require('net'); var s ...

  4. 使用泛型定义一个可重用的Dao

    dao用来和数据库进行交互,一个项目中,可能有用户表,产品表等等,不可能为每一个表都建立一个dao,使用泛型可以实现通吃. UserDao.java public class UserDao < ...

  5. 我的Shell + VIM配置

    1. 安装powerline-shell 下载powerline-shell # cd /opt/ # git clone https://github.com/milkbikis/powerline ...

  6. 卸载RedHat7自带的yum,安装并使用网易163源

    由于redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,安装CentOS yum工具,再配置其他源,以下为详细过程: 删除redhat原有的yu ...

  7. Linux 确定系统glibc版本

    在shell中,可以直接运行glibc共享库文件获取glibc版本,CentOS下执行: /lib/libc.so. 输出为: GNU C Library stable release version ...

  8. display: inline-block 的神奇效果

    先上要实现的效果图: 方案一:来自卢兄: <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  9. (转)PHP中文处理 中文字符串截取(mb_substr)和获取中文字符串字数

    一.中文截取:mb_substr() mb_substr( $str, $start, $length, $encoding ) $str,需要截断的字符串 $start,截断开始处,起始处为0 $l ...

  10. Could not parse mapping document from resource cn/spt/model/Student.hbm.xml

    初始hibernate, 写第一个程序 helloworld的错误: Exception in thread "main" org.hibernate.InvalidMapping ...