You may want to try dealing with constraints. I have only done a minimal amount of work with constraints, so I'm not sure if they can be used dynamically, but its just an idea.