views:

203

answers:

1

I have a UIImageView that I create progmatically right? Works like a charm when I initWithImage and set the parameters for scaling to UIViewContentModeScaleToFill. I can scale all day long and create many different smaller 'thumbprint' sized versions of the UIImageView at whim, HOWEVER when I add subviews to said UIImageView and then try to scale the happy new parent the child subview does not scale! I looked around and found that I should enable the setAutoresizingSubviews boolean of the parentView to true (Which I did) and then call:

ChildView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

Which I also did... now when I scale the parent view the child also scales but crazy wacked out like and goes all over the place (Not a very good way of putting it) but my point is that I assumed the child would scale proportionally to the parent and stay in the same place (Which it doesn't)

My question is how do I set up my code so that when I scale my parent view by 1/4 or w/e to make a thumbprint of the view the children subviews that the parent view owns will scale accordingly and allow the 1/4 sized thumbprint to look just like the full sized view (Just smaller).

A: 

To scale subviews, you need to set the affine transform of the view to scale the contents instead of using the content mode.

The autoresizing mask isn't for scaling subviews. Instead, it's a springs-and-struts model for how to position and resize the frame of subviews when the parent view is resized. Mostly it's used when the view autorotates from landscape to portrait and vice-versa.

What you're trying to do is scale the content of the view. So instead of using UIImageView, which is optimized for displaying images, I would create a custom subclass of UIView, and then in the initialization, set the view's transform with this code:

self.transform = CATransform3DMakeScale(zoom, zoom, 1.0f);

Then put the subviews in. You can re-set the transform and the subviews will stay in the same positions relative to each other, but at a different scale.

lucius
Thank you so much for your help lucius, I'm trying to get the quartz library to compile correctly... I included the framework and included QuartzCore.h but I'm still getting a "Incompatible type for argument 1 of 'setTransform'", and so until I figure it out I wont be able to test this out. But i'll be back to this post as soon as I can
Parad0x13
`self.transform` turns into [self setTransform:...] so it make sure you're sending the message to the correct class of object. The zoom variable should be a CGFloat.
lucius