Dev Juice: Help me fix my UIView animations

Dear Dev Juice,

I’m having an issue with UIView animations, that I’m struggling to describe in keywords, so I can’t find anything helpful with Google. The problem is that I can’t seem to work out how to make a UIButton move relative to the bottom of the parent view, as I shrink the parent view.

I’ve managed to get the other views inside the parent to scale with an autoresize mask, but I cannot for the life of me work out how to make the bottom (or even center) of my button clip on to the bounds of the view.

Not sure if that accurately paints the picture, and I’m not sure if it’s relevant, but I’m making a widget for NotificationCenter. Hope you can help, I’m tearing my hair out.

Thanks,

Rory W.

Dear Rory,

It’s still the autoresizing mask you have to deal with, but you need to be working with the struts instead of the springs.

The Autosizing pane in Interface Builder lets you establish a fixed distance between a view and its parent’s edge. Imagine setting a view at 40 points from the top and left of the superview. Enabling the top and left struts in the inspector fixes that view at its relative position. When you use a right or bottom strut, those distances are also maintained. The view must either move or resize to stay the same distances from those sides.

The equivalents of struts in code are UIViewAutoresizingFlexibleLeftMargin, UIViewAutoresizingFlexibleRightMargin, UIViewAutoresizingFlexibleTopMargin, and UIViewAutoresizingFlexibleBottomMargin.

These flags allow a view to resize by expanding or shrinking in the direction of a given margin without affecting the size of any items inside. Although each of these correspond to the struts of Interface Builder’s Autosizing pane, they act in the opposite way. In IB, struts fix the margins; the flags allow flexible resizing along those margins.

Enjoy your afternoon sip of Dev Juice!

Dev Juice: Help me fix my UIView animations originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 21 Jun 2011 20:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Leave a Reply

Your email address will not be published. Required fields are marked *