0

我根据数组计数将多个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];
}
}
4

1 回答 1

0

在记住单击时,您可以删除所有子视图按钮,如下所示:

while ([self.scrollView viewWithTag:[button tag]] != nil)
        [[self.scrollView viewWithTag:[button tag]] removeFromSuperview];

现在,开始减少显示记忆卡的频率。定义一个与原始数组长度相同的布尔数组。将记住的卡片设置为 YES 值,将未记住的卡片设置为 No 值到其在数组上的相应位置。

我会继续编辑。

于 2013-10-20T11:15:14.073 回答