0
votes

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

2
Why do you want to increase the UIImageView's frame without affecting the image displayed? Sounds like you really want to affect the way it processes events, not its appearance. What specific effect are you trying to acheive? Have the image remain highlighted when the user moves her finger outside of the frame? - Andrew Pouliot

2 Answers

0
votes

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.

0
votes

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

imageView.contentMode = UIViewContentModeCenter;