Skip to Content

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!



 

Add a Comment

*0 / 3000 Character Maximum Comment Moderation Enabled. Your comment will appear after it is cleared by an editor.

4 Comments

Filter by:
Ric

I love reading the good words of the doctor here, Erica Sadun. I study, read, code, and design to be able to talk the code someday like you do. Keep talking, you make hard code fun.

June 21 2011 at 11:58 PM Report abuse rate up rate down Reply
gormster

Wait, you can make Notification Center widgets? How?

June 21 2011 at 9:40 PM Report abuse rate up rate down Reply
1 reply to gormster's comment
yozzozo

Yeah, Notification center has a plugin interface, like many other Apple built-in iOS features (such as Lock Screen plugins). They haven't provided a public SDK for it, so making a widget is a jailbreak-only thing. Documentation for it is available on the web in places. See http://www.jailbreaknation.com/top-notification-center-jailbreak-widgets/

June 22 2011 at 2:13 PM Report abuse rate up rate down Reply
TUAWSteve

Can we haz TUAW Dev Juice shirts made? Please?

June 21 2011 at 9:13 PM Report abuse rate up rate down Reply
Buy an ad here

Tweets

© 2012 AOL Inc. All Rights Reserved.