tags:

views:

1015

answers:

2

Hi

I have a custom UIImageView class which I use to handle multi-touch events on the UIImageView. When the user touch begins, I want to increase the UIImageView's frame but keep the UIImage size fixed.

I tried changing the UIImageView's frame and then calling the drawInRect: method of UIImage to keep the UIImage's size fixed. But this is not working.

The contentMode for the UIImageView is set as ScaleAspectFit and as soon as I increase the frame size of the UIImageView, the UIImage size also increases (and is not affected by the drawInRect:)

Can someone please tell me how I can achieve this?

Thanks.

Adding more details

What I am trying to do is this

  1. Place a UIImageView on the screen with the size same as the size of the image

  2. When the user selects the image, anywhere he touches, the image edits as if the user is doing multi-touch with the image

If I increase the size of the imageview to detect touches any where, the image size also increases... Hope that makes things clearer!

Thanks

A: 

There may well be other ways to do it, but I think the UIImageView is doing what it's intended to do here. What do you want the area of the view not covered by the image to look like? Be transparent? Have a solid colour? Why do you want to do this? Is it to capture touch events from a wider area than that under the image itself?

If you have a good reason for needing to do this I would create a new view, probably just a plain UIView (with background set to transparent colour), and add the UIImageView to that. Make the plain view the one you resize.

Phil Nash
Thanks. Yes i want to capture touch events from a wider area and apply them to the imageview so it gives a feel that the image view's touchable area is much larger than it actually is. i have put the imageview inside a UIView with a transparent bkg but I cant get the transforms to be applied to imageview for touches on the uiview.
lostInTransit
try setting the bkg to 0.1 opacity, I think if it's 0 alpha it doesn't register touch events
Steve Tranby
@Steve: no, an alpha of 0 is fine - you just have to make sure that userInteractionEnabled is set to YES
Phil Nash
@lostInTransit: are you changing the size of the UIImageView (ie, its frame)?
Phil Nash
@lostInTransit: wait a minute - you didn't want the UIImageView to change, did you? just the UIView it sits in
Phil Nash
Added the details in the ques. thanks
lostInTransit
A: 

I haven't specifically tried this, but I think it would work:

imageView.contentMode = UIViewContentModeCenter;
Daniel Dickison