0

我正在创建一个包含图像的水平滚动表格视图。我的滑动功能运行良好,并且能够将图像添加到scrollView如下所示cellForRowAtIndexPath

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tv.frame.size.width, 78)];
    [scrollView setContentSize:CGSizeMake(700, 78)];
    UIImage *footImage = [UIImage imageNamed:@"Foot.png"];
    UIImageView *footImageView = [[UIImageView alloc] initWithImage:footImage];
    footImageView.frame = CGRectMake(0, 0, 80, 78);
    footImageView.userInteractionEnabled = YES;
    [scrollView addSubview: footImageView];

    UIImage *handImage = [UIImage imageNamed:@"Hand.png"];
    UIImageView *handImageView = [[UIImageView alloc] initWithImage:handImage];
    handImageView.frame = CGRectMake(90, 0, 80, 78);
    handImageView.userInteractionEnabled = YES;
    [scrollView addSubview: handImageView];

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(highlightImage)];
    [scrollView addGestureRecognizer:tapGesture];
    NSLog(@"tapGesture added to scrollView");


    [[cell contentView] addSubview:scrollView];

    pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 50, tv.frame.size.width, 50)];
    [pageControl setNumberOfPages:4];
    [[cell contentView] addSubview:pageControl];

tapGesture正在向选择器注册hightlightImage,并且只是记录它正确调用此方法。

- (void) highlightImage
{
    NSLog(@"tapping tapping");
}

真正在努力的是能够在点击时突出显示/选择这些图像,如果再次点击则突出显示/取消选择它们。我将在屏幕上有另一个按钮导航到下一页(此处无关)。

我在这里走正确的道路吗?显然,我将填充一个NSArrayofUIImages并以scrollView这种方式填充,但现在只是将其添加出来。如果有人可以给我一些指导或示例,说明如何使每个按钮分别可选择/取消选择,那就太好了:)

4

1 回答 1

2

使用 UIButton 而不是 UIImageView。

它具有内置selected功能。

摆脱您的手势并将 highlightImage 添加为每个按钮的操作。

让你highlightImage成为highlightImage:(id)sender

发件人应该是一个按钮,所以你可以做

[发件人 setSelected:YES];

于 2011-02-27T01:54:54.067 回答