2010-11-25 65 views
0

嗨我已经与图像填充uiscrollview(代码是波纹管),但我不知道如何添加一些事件内的图像。我想要在scrollview内部双击图片并获取一些事件。任何方向如何实现这一目标?如何捕捉图像上的uiscrollview内的事件

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..."); 

回答

2

将UITapGestureRecognizer添加到UIImageView(s)。

查看this guide了解更多信息。

+0

但根据iCodeBlog的uiimageview不会得到水龙头,所以你可能不得不把uiimageview到另一个uview。 – harshalb 2010-11-25 08:39:04