实现UIScrollView循环滚动的三种方法
来源:互联网 发布:网络助手无法校正流量 编辑:程序博客网 时间:2024/05/06 08:53
1.循环滚动
初始化UISCrollView
float x,y,width,height;
x = WIDTH_OFF_SET;
y = HEIGHT_OFF_SET;
width = WIDTH_OFF_SET;
height = SCROLLVIEW_HEIGHT;
for (int j=0; j<3; j++) {
UIView
[view setTag:10+j];//view的tag为10,11,12
[view setBackgroundColor:[UIColor yellowColor]];
for (int i=0; i<count; i++) {
UIButton*pointNButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
[pointNButton setTitle:[NSString stringWithFormat:@"%d",100+i]forState:UIControlStateNormal];
[pointNButton setBackgroundColor:[UIColor blueColor]];
[pointNButton setTag:100+i];
[pointNButton setFrame:CGRectMake(6.5+(13+65)*i, 8, 65,65)];
[pointNButton addTarget:self action:@selector(pointBtnClicked:)forControlEvents:UIControlEventTouchUpIns
[view addSubview:pointNButton];
}
[scrollView addSubview:view];
[view release];
}
[scrollView setDelegate:self];
[scrollView setPagingEnabled:NO];
[scrollView setContentSize:CGSizeMake(WIDTH_OFF_SET*3,80.0)];
[scrollView setShowsHorizontalScroll
#define WIDTH_OFF_SET630.0
#define HEIGHT_OFF_SET0
#define SCROLLVIEW_WIDTH390.0
#define SCROLLVIEW_HEIGHT80.0
if(x < 0) x = pageWidth * 2;\
if(x > pageWidth * 2) x = 0.0f;\
[ARTICLEX setFrame:CGRectMake(x, \
ARTICLEX.frame.origin.y,\
ARTICLEX.frame.size.width,\
ARTICLEX.frame.size.height)]
#pragma mark -
#pragma mark UIScrollViewDelegate
//将三个view都向右移动,并更新三个指针的指向,article1永远指向当前显示的view,article0是左边的,article2是右边的
- (void)allArticlesMoveRight:(CGFloat)pageWidth {
UIView *view1 = [scrollView viewWithTag:11];
UIView *view2 = [scrollView viewWithTag:12];
}
- (void)allArticlesMoveLeft:(CGFloat)pageWidth {
UIView *view0 = [scrollView viewWithTag:10];
UIView *view1 = [scrollView viewWithTag:11];
UIView *view2 = [scrollView viewWithTag:12];
}
- (void)scrollViewDidScroll:(UIScrollView *)theScrollView
{
}
- (void)scrollViewDidEndDecelera
{
}
2.种方法思想是一样的,运用scrollRectToVisible
- (void)scrollViewDidEndDecelera
{
float currentPage =scrollView.contentOffset.x;
NSLog(@"=======bao===scrollViewDidEndDragging
if (currentPage>WIDTH_OFF_SET&¤tPage<WIDTH_OFF_SET*2){
[scrollViewscrollRectToVisible:CGRectMake(0,0,SCROLLVIEW_WIDTH,SCROLLVIEW_HEIGHT)animated:NO];
} else if (currentPage<0) {
[scrollViewscrollRectToVisible:CGRectMake(WIDTH_OFF_SET,0,SCROLLVIEW_WIDTH,SCROLLVIEW_HEIGHT)animated:NO];
}
}
3。改变conentOffset
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)_scrollView
{
int currentPage =(int)scrollView.contentOffset.x;
if (currentPage >WIDTH_OFF_SET) {
scrollView.contentOffset =CGPointMake(abs(currentPage-WIDTH_OFF_SET), HEIGHT_OFF_SET);
} else if (currentPage<0) {
scrollView.contentOffset =CGPointMake(currentPage+WIDTH_OFF_SET,HEIGHT_OFF_SET);
}
}
- (void)scrollViewDidEndDecelera
{
int x=(int)scrollView.contentOffset.x/BUTTON_OFFSET*BUTTON_OFFSET;
[scrollView setContentOffset:CGPointMake(x, HEIGHT_OFF_SET)animated:YES];
}
- (void)scrollViewDidEndDragging
if (!decelerate) {
int x =(int)scrollView.contentOffset.y/BUTTON_OFFSET*BUTTON_OFFSET;
[scrollView setContentOffset:CGPointMake(x, HEIGHT_OFF_SET)animated:YES];
}
}
总之要想实现无缝链接就必须准备三屏你的数据,通过改变offset或是view的frame的的横纵坐标进而实现循环滚动
- 实现UIScrollView循环滚动的三种方法
- 实现UIScrollView循环滚动的三种方法
- 实现UIScrollView的循环滚动
- 利用UIScrollView实现循环滚动翻页的方法
- 利用UIScrollView实现循环滚动翻页的方法
- 实现UISCrollView循环滚动
- 实现UIScrollView循环滚动
- UIScrollView实现循环滚动
- 实现UIScrollView循环滚动
- UIScrollView的循环滚动
- UIScrollView代码实现循环滚动
- UIScrollView代码实现循环滚动
- iOS UISCrollView循环滚动 实现
- UIScrollView实现循环滚动---快捷方式
- UIScrollView实现循环滚动(一)
- UIScrollview 无缝循环滚动实现
- UIScrollView代码实现循环滚动
- iOS UISCrollView循环滚动 实现
- CCS v5.2+SEED-DEC6713+SEED-XDS560PLUS+DEC6713_CODEC Test
- 对潇潇暮雨洒江天,一番洗清秋。渐霜风凄紧,关河冷落,残照当楼。是处红衰翠减,苒苒物华休。唯有长江水,无语东流。不忍登高临远,望故乡渺邈,归思难收。叹年来踪迹,何事苦淹留?想佳人,妆楼颙望,误几回、天际
- Cocos2dx游戏源码合集(BY懒骨头+持续更新+2014.02.21)
- 经典智力题:经理年龄问题
- pymongo针对字段的一些操作
- 实现UIScrollView循环滚动的三种方法
- Unique Binary Search Trees
- [Excel使用技巧]Excel的宏安全性不能修改
- Android 之ExpandableListView几个特殊的属性
- 人人网
- RTTI(runtime type information Identification) 运行时类型识别
- 移植USB无线网卡到 mini2440
- 【cocos2dx-3.0beta-制作flappybird】未雨绸缪—Loading界面的写法
- java - cp