tags:

views:

39

answers:

2

I'm trying to work with a scroll view controller that needs to adjust it's contents based on user interaction -- specifically, by adding a 'done' button while the user is working with a UITextView, then removing it when they are done. The problem is making room for the button in question. What I'd like to do is...

control.layer.position.x-=50;

for every single control that is 'below' the one I'm working with. Unfortunately, that doesn't work. As far as I can tell, I'm going to have to do something more like...

control.layer.position=CGPointMake(newX, newY);

This creates a maintainability nightmare; instead of being able to rearrange buttons inside UIBuilder at will, I'm going to have to change their positions in the code as well. Unfortunately, no matter what variant of the first type of code I use, the result doesn't work; I'm informed that I need an lvalue to the left of the assign or that I'm trying to manipulate incompatible types.

+1  A: 

It'll be more verbose than the -= solution, but why don't you just calculate newX and newY based on their old values?

e.g.

CGPoint oldPosition = control.layer.position;
control.layer.position = CGPointMake(oldPosition.x - 50, oldPosition.y);
zem
Tried that; that's when I received the incompatible data type errors.
RonLugge
@RonLugge can you post the error in detail? this is just like your second example, except for the expressions passed to CGPointMake.
zem
@RonLugge Wait... CGLayers don't have properties. Why are you trying to set the position property on the layer instead of the control?
zem
Erm... the button itself doesn't have a position; it's the layer that is one of it's property that does. I retried your approach, and it's actually working, even though there shouldn't be a semantic difference between it and what I actually did (control.layer.position = cgpointmake(control.layer.position.x - 50, y)
RonLugge
A: 

The button comes with a center property, so:

button.center = CGPointMake(button.center.x - 50, button.center.y); 

should do the trick

ohho