不使用UIButton触摸图片的事件

时间:2011-09-11 17:14:20

标签: objective-c xcode cocoa-touch uibutton ibaction

是否可以在不使用UIButton的情况下注册图片?如果是的话,我该怎么做?

我可以考虑更改代码中按钮的背景,然后使用IBAction来检测触摸。

是的,对不起我的英语。

1 个答案:

答案 0 :(得分:0)

不确定。您可以在UIImageView上放置UITapGestureRecognizer(请记住将图像视图的userInteractionEnabled属性设置为YES):

// assumes "myImageView" is your UIImageView that has user interaction enabled
UITapGestureRecognizer * tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)] autorelease];
[myImageView addGestureRecognizer:tap];
稍后在你的控制器中......

- (void)tap:(UITapGestureRecognizer *)recognizer 
{
    // whatever you want
}

但是,您可以将UIButton设置为基本上是一个愚蠢的图像。只需将背景图像设置为正常状态,禁用所有调整突出显示和触摸,您应该具有您正在考虑的内容。

如果我误解了你的目标,请随时澄清。