Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ts91

macrumors newbie
Original poster
Jul 25, 2012
4
0
Hi,

I am new to objective-c and have completed a few tutorials which I am now adapting to learn more!

I have a button (which was made via the interface builder) which I am moving randomly using the following code.

Code:
button.center = CGPointMake(arc4random_uniform(200), arc4random_uniform(500));

However after the button is pressed it reverts to the original position that the button was from the interface builder. I've found turning off auto layout will sort it but figured there would be another way?

Hope someone can point me in the right direction!

Thanks
 
I've found turning off auto layout will sort it but figured there would be another way?

Not really. If you don't want auto-layout to apply, you need to turn it off. Either that or you need to adjust the auto-layout constraints (which can be done programmatically) to allow your button to have different positions.
 
Not really. If you don't want auto-layout to apply, you need to turn it off. Either that or you need to adjust the auto-layout constraints (which can be done programmatically) to allow your button to have different positions.

Ahh ok, is it generally advised to leave auto-layout off in most circumstances then?
 
...is it generally advised to leave auto-layout off in most circumstances then?

Generally advised? I wouldn't say so. (Others may disagree). I think it's just a matter of personal preference and needs of the app (Auto Layout only supported in iOS 6).
 
Auto layout and animation. Questions:

Not really. If you don't want auto-layout to apply, you need to turn it off. Either that or you need to adjust the auto-layout constraints (which can be done programmatically) to allow your button to have different positions.

I haven't used auto layout much (My company is targeting iOS >= 5.0 for now, and AutoLayout requires iOS 6.)

What do you do about animating views using UIView animation with AutoLayout? I've seen posts from various people about views snapping back to their original positions when they use it.

Can you turn off auto layout on a view-by-view basis? From what I've seen, it's a setting for an entire XIB file or storyboard.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.