本文介绍了如何在 iOS 中使 uiscrollview 无限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想像那样滚动 1 2 3 1 2 3
I want to scroll like that 1 2 3 1 2 3
我有一些按钮,假设有 10 个,我想在无限滚动中显示它们.
I have some buttons suppose 10 which i want to show on endless scroll.
numbercolors=[[NSMutableArray alloc] init];
//total count of array is 49
numbercolors = [NSMutableArray arrayWithObjects:@"25",@"26",@"27",@"28",@"29",@"31",@"32",@"33",@"34",@"35", @"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35", @"0",@"1",@"2",@"3",nil];
int x=2500;
for (NSInteger index = 0; index < [numbercolors count]; index++)
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(x ,0,29.0,77.0);
button.tag = index;
[button setTitle:[numbercolors objectAtIndex:index] forState:UIControlStateNormal];
[button addTarget:self action:@selector(didTapButton:)
forControlEvents:UIControlEventTouchUpInside];
[coloringScroll addSubview:button];
x=x+70+29;
}
[coloringScroll setContentSize:CGSizeMake(5000+ (29+70)*[numbercolors count], 1)];
[coloringScroll setContentOffset:CGPointMake(2500+(29+70)*11, 0)];
这是我在滚动视图上制作按钮的代码.
This is my code for make butttons on scrollview.
如何在 - (void)scrollViewDidEndDecelerating:(UIScrollView *)sender 这个方法中设置无限滚动.
How can I set in - (void)scrollViewDidEndDecelerating:(UIScrollView *)sender this method for infinite scroll.
推荐答案
只需要设置setContentOffset count
Just need to do set setContentOffset count
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.x > 2500+(29+70)*4 + ((29+70)*36)) {
[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x-((29+70)*36), 0)];
}
if (scrollView.contentOffset.x < 2500+(29+70)*4){
[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x+((29+70)*36), 0)];
}
}
这篇关于如何在 iOS 中使 uiscrollview 无限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!