在滚动视图中获取触摸事件的图像视图

时间:2010-10-05 08:57:55

标签: iphone

我有一个uiscrollview,我正在展示一些动态生成的uiimageview。现在我想在任何这些图像上触摸操作。我尝试使用touchbegn方法,但它没有被调用。请告诉我我做错了什么。

int numofRows = [arrMyPhotos count]/3;
    if([arrMyPhotos count]%3>0)
        numofRows++;
    scrlPhotoList.contentSize = CGSizeMake(320, numofRows*100);
    for(int i = 0;i<numofRows;i++) {
        x = 10;
        j = 0;
        while (j<3 && k<[arrMyPhotos count]) {
            NSString *pngFilePath = [[NSString stringWithFormat:@"%@/",docDir] stringByAppendingFormat:@"%@",[(NSDictionary*)[arrMyPhotos objectAtIndex:k] objectForKey:@"picName"]];
            NSLog(@"%@",pngFilePath);
            UIImage *img = [UIImage imageWithContentsOfFile:pngFilePath];
            if(img!=nil) {
                UIImageView *imgVw = [[UIImageView alloc] init];
                imgVw.image = [self imageByScalingAndCroppingForSize:CGRectMake(0, 0, 95, 95) image:img];
                imgVw.tag = k;
                imgVw.frame = CGRectMake(x, y, 95, 95);
                imgVw.userInteractionEnabled = TRUE;
                imgVw.multipleTouchEnabled = TRUE;

                [scrlPhotoList addSubview:imgVw];
                //k++;
                x = x+105;
                j++;
            }
            k++;
        }
        y = y+105;
    }
    [self.view addSubview:scrlPhotoList];



-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    UITouch *touch = [[event allTouches] anyObject];
    //CGPoint touchLocation = [touch locationInView:self.view];

    if(([touch view]).tag>0) {
        NSLog(@"%d",([touch view]).tag);
    }
}

1 个答案:

答案 0 :(得分:0)

您的代码似乎位于UIControllerView中,用于处理您想要实现触摸和控制器的视图所需的触摸事件!

如果你想要什么,是一个基本的触摸事件,你需要有UIButton或其他支持触摸事件的UIView