如何在图像上捕获uiscrollview内的事件

时间:2010-11-25 08:24:45

标签: iphone objective-c

您好我已经使用图像填充uiscrollview(代码如下)但我不知道如何向内部图像添加一些事件。我想在scrollview中双击图像并获得一些事件。任何方向如何实现这一目标?

arrayOfImages = [[NSMutableArray alloc] init];
    NSString *img;
    for (img in imgArray)
    {
        [arrayOfImages addObject:[UIImage imageNamed:img]];
    }

    NSLog(@"Array initialization complete...");

    scrollView = [[UIScrollView alloc] init];
    scrollView.scrollEnabled = YES;
    scrollView.pagingEnabled = YES;
    scrollView.directionalLockEnabled = YES;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.delegate = self;
    scrollView.backgroundColor = [UIColor blueColor];
    scrollView.autoresizesSubviews = YES;
    scrollView.frame = CGRectMake(0, 0, 320, 29);
    [self.view addSubview:scrollView];

    NSLog(@"Scroll View initialization setup complete...");

    UIImage *imageToAdd;
    int x = 0;
    int y = 0;
    for (imageToAdd in arrayOfImages)
    {
        UIImageView *temp = [[UIImageView alloc] initWithImage:imageToAdd];     

        temp.frame = CGRectMake(x, y, 29, 29);
        x += 29;
        [scrollView addSubview:temp];

    }

    NSLog(@"Adding images to outlet complete...");

1 个答案:

答案 0 :(得分:2)

将UITapGestureRecognizer添加到UIImageView(s)。

请查看this guide以获取更多信息。