开发者

Touch event of a picture without using UIButton

Is it possible to register a touch of a picture wit开发者_运维百科hout using UIButton? And if it is, how can i do this?

I can just think of changing the background of a button in the code, and then use IBAction to detect the touch.

Btw, sorry for my english.


Sure. You can put a UITapGestureRecognizer on a UIImageView (remember to set the image view's userInteractionEnabled property to YES):

// assumes "myImageView" is your UIImageView that has user interaction enabled
UITapGestureRecognizer * tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)] autorelease];
[myImageView addGestureRecognizer:tap];

later in your controller...

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

However, you can set up a UIButton to basically be a dumb image. Just set the background image for the normal state, disable all the adjusting on highlighting and touches, and you should have exactly what you're thinking of.

If I've misunderstood what you're getting at, feel free to clarify.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜