我根据数组计数将多个UIButton
(作为卡片)作为子视图放入,从数据库中获取。UIScrollView
除此之外,我能够成功开发无限滚动并且它工作正常。所以我有一个叫做“记住”的选项。一旦我点击记住,卡片(UIButton
作为子视图)在滚动中的出现频率必须降低。UIScrollView
我怎样才能实现这一点,即特定索引处的数组必须在.任何逻辑或想法中较少显示?这是我的代码,直到无限滚动:
-(void)createCards
{
[self addCardWithName:[NSString stringWithFormat:@"%@",[entryArray objectAtIndex:
([entryArray count]-1)]] atPosition:0];
for (int i = 1; i < ([entryArray count]+1); i++) {
NSString *titleString = [NSString stringWithFormat:@"%@",[entryArray objectAtIndex:i-1] ];
UIButton *buttonView1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[buttonView1 setFrame:CGRectMake(i*320, 0, 320, 180)];
[buttonView1 setTitle:titleString forState:UIControlStateNormal];
buttonView1.tag=i;
[scrollViewForCard addSubview:buttonView1];
}
[self addCardWithName:[NSString stringWithFormat:@"%@",[entryArray objectAtIndex:0]] atPosition:([entryArray count]+1)];
scrollViewForCard.contentSize = CGSizeMake(480*([entryArray count]+1), 180);
[scrollViewForCard scrollRectToVisible:CGRectMake(320,0,320,180) animated:NO];
}
- (void)addCardWithName:(NSString*)titleString atPosition:(int)position
{
UIButton *buttonView1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[buttonView1 setFrame:CGRectMake(position*320, 0, 320, 180)];
[buttonView1 setTitle:titleString forState:UIControlStateNormal];
[scrollViewForCard addSubview:buttonView1];
}
#pragma mark scroll view-delegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
int randomInt2 = arc4random() % [entryArray count];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender
{
if (sender.contentOffset.x == 0) {
[sender scrollRectToVisible:CGRectMake((320*[entryArray count]),0,320,180) animated:NO];
}
else if (sender.contentOffset.x == ([entryArray count]+1)*320) {
[sender scrollRectToVisible:CGRectMake(320,0,320,180) animated:NO];
}
}