0

我正在开发一个应用程序,我想要的是当用户单击图像视图中的图像时

应该触发一个动作(例如单击按钮时)。

我不想要按钮图像。我只想要一个图像视图和操作。

请帮忙。

4

2 回答 2

4
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
    singleTap.numberOfTapsRequired = 1;
    imageView.userInteractionEnabled = YES;
    [imageView addGestureRecognizer:singleTap];
    [singleTap release];


-(void)tapDetected{
    NSLog(@"single Tap on imageview");

}
于 2012-06-13T10:25:38.113 回答
0

根据您的评论,如果您想了解图像的索引,那么您可以通过tag图像视图的属性来做到这一点。根据需要分配图像视图的tag属性并获取tagon Touch 事件

例如 :

添加UITapGestureRecognizer

ITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                action:@selector(tap:)];
tap.numberOfTapsRequired = 1;

[self addGestureRecognizer:tap];

[tap release];

使用它的委托方法:- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event

// called when touch is began or when user touches 
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    UITouch *touch = [touches anyObject]; 

    int indexOfImageView = touch.view.tag;
}

希望对你有帮助...

于 2012-06-14T05:32:15.533 回答