如何让一个imageview做一个segue

时间:2012-10-05 07:40:11

标签: objective-c ios gridview uiimageview

我在gridview中生成了一堆imageview。但是现在我希望每个imageview可以做到另一个屏幕。有人知道我怎么做吗?这是我如何生成我的imageview并将其放入网格的代码。

UIImageView * myView = [[UIImageView  alloc] initWithImage:myImage];
        CGRect rect = myView.frame;
        rect.origin.x = xCurrent;
        rect.origin.y = yCurrent;
        myView.frame = rect;
        myView.tag = cellCounter;
        [gridContainerView addSubview:myView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];

        myView.userInteractionEnabled = YES;

        [myView addGestureRecognizer:tap];

请帮忙

亲切的问候

2 个答案:

答案 0 :(得分:6)

您正在寻找tapGestureRecognizer。将其中一个添加到图像视图中,然后将操作调用为segue方法。

UIImageView *img = [[UIImageView alloc] init];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mySequeMethod:)];

img.userInteractionEnabled = YES;

[img addGestureRecognizer:tap];

答案 1 :(得分:0)

A:

使用自定义按钮代替UIImageView,并设置图像......然后使用该按钮进行segue(看起来相同)


B:

在视图中使用手势识别器,并用一根手指敲击。