ios中滚动页面
2024-10-19 08:59:48
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
int width=frame.size.width;
int height=frame.size.height;
scrollview=[[UIScrollView alloc] initWithFrame:CGRectMake(, , width, height)];
[self addSubview:scrollview];
for (int i=; i<; i++) {
UIImageView *imageview=[[UIImageView alloc] initWithFrame:CGRectMake(i*width, , width, height)];
imageview.image=[UIImage imageNamed:[NSString stringWithFormat:@"image%zi@2x.jpg",(i+)]];
[scrollview addSubview:imageview];
}
scrollview.contentSize=CGSizeMake(*width, height);
scrollview.pagingEnabled=YES;
scrollview.showsVerticalScrollIndicator=NO;
scrollview.showsHorizontalScrollIndicator=NO;
scrollview.delegate=self;
scrollview.bounces=NO; pagecontroller=[[UIPageControl alloc] initWithFrame:CGRectMake((width-)*0.5f, height--, , )];
[self addSubview:pagecontroller]; pagecontroller.currentPage=;
pagecontroller.numberOfPages=;
currentPage=; self.timer=[NSTimer scheduledTimerWithTimeInterval: target:self
selector:@selector(timer:) userInfo:nil repeats:YES];
[self.timer fire]; }
return self;
} -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
CGFloat width=self.bounds.size.width;
CGPoint point=scrollview.contentOffset;
CGFloat offenx=point.x;
pagecontroller.currentPage=offenx/width;
} -(void)timer:(NSTimer *)time{
if (currentPage>) {
currentPage=;
}
CGFloat width=self.bounds.size.width;
[UIView beginAnimations:nil context:nil];
scrollview.contentOffset=CGPointMake(currentPage*width, );
pagecontroller.currentPage=currentPage;
[UIView commitAnimations];
currentPage++;
}
最新文章
- 精通Web Analytics 2.0 (7) 第五章:荣耀之钥:度量成功
- ExtJs 学习之开篇(三)Ext.grid.Panel表格中的处理
- CentOS6.5菜鸟之旅:VIM插件NERDtree初探
- lua 的 WriteFile 和 ReadFile
- 函数 stat() 详解
- MVC中的Ajax(AjaxHelper)
- php 防止SQL注入函数
- 利用sql 存储过程把表中内容自动生成insert语句
- git(创建,提交,回退)
- lua table表
- nodejs模块引用
- PHP+XML写注册登录
- redis复习
- hdu 4643 GSM 计算几何 - 点线关系
- Linux-C语言标准输入输出
- Spark源码分析之Checkpoint的过程
- 20155217 实验四《Java面向对象程序设计》实验报告
- Spring MapFactoryBean例子
- Solidworks to Urdf to Sdf
- session和cookie基本操作
热门文章
- DevExpress ChartControl控件实现图表【转】
- 原生JS实现new方法、new一个对象发生的四部、new里面常用的优先级
- (转) Unity3D 使用Texturepacker打包工具制作NGUI(Atlas)图集
- nod32的内网在线更新设置
- idea中的maven模块变成灰色的可能原因
- windows命令行的使用,去掉";半";字
- mysql 表分区 查看表分区 修改表分区
- iOS 真机上图标不显示
- 微软BI 之SSAS 系列 - 实现Cube 以及角色扮演维度,度量值格式化和计算成员的创建
- 使用Json.Net解决MVC中各种json操作