views:

108

answers:

1

I have a UIImageView. In IB I attached a 'Touch Up' event on this UIImageView to call an IBAction in my code. This all works fine.

In some cases I need to resize this UIImageView in my code. I do this by settings it's 'frame' property. The resizing works fine. The problem is that the 'touch area' stayed the original size.

What I mean is that let's say I start with a UIImageView of 100x100:

***
***
***

Then resize it to 200x100:

***xxx
***xxx
***xxx

In this case the UIImageView shows up in the entire area (* and x) but the touches only respond in the original area (represented by *).

How can I also resize the area that responds to touch events?

EDIT: I should also mention that I move the UIImageView's origin as well, in case that makes a difference.

A: 

In IB I attached a 'Touch Up' event on this UIImageView to call an IBAction in my code. This all works fine.

Uhhh no it does not. Touch up events can only be sent to UIControl subclasses, which UIImageView is not.

So I think you are confused and you might have more views than you think. Have you maybe added a transparent button on top of your image that you forgot to resize?

Note that you can also use a UIButton with an image set if you need 'image button' behaviour.

St3fan
Yeah you're right, silly mistake on my part. There was a UIButton on top there. Someone else had edited this in IB so I got confused. I was naive to assume that all UIView subclasses could be interacted with. Anyways, I'll mark this as accepted and burry my head in the ground. Thanks.
Nebs