UIButton moving back to original position?

Discussion in 'iOS Programming' started by ts91, Apr 17, 2013.

  1. ts91 macrumors newbie

    Joined:
    Jul 25, 2012
    #1
    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
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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.
     
  3. ts91 thread starter macrumors newbie

    Joined:
    Jul 25, 2012
    #3
    Ahh ok, is it generally advised to leave auto-layout off in most circumstances then?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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).
     
  5. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #5
    Auto layout and animation. Questions:

    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.
     

Share This Page