The problem is that in new projects in iOS 6 / Xcode 4.5, the "Autostart" function is enabled by default. Autolayout is a replacement for "Springs and Struts" (but it only works with iOS 6). This function adds restrictions to the view, which takes precedence over the move that you tried to execute in your code.
So there are three possible fixes:
1) Create new button restrictions programmatically. Autolayout is pretty powerful and flexible ... especially if you're trying to keep track of iPhone 5 and earlier. You can find more information on how to do this by watching the WWDC video: Introduction to auto-layout for iOS and OS X
2) Do not use Autolayout. Select the view in your storyboard, and in the "File inspector" uncheck the "Use self-timer" box.
3) Create IBOutlets for each of the restrictions on the button. Then, before moving the button, remove these restrictions:
@interface MyViewController : UIViewController @property (weak, nonatomic) IBOutlet UIButton *addMoreFieldsBtn; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *hConstraint; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *vConstraint; - (IBAction)addMoreFields:(id)sender; @end
and...
-(void)movePlusButton { NSLog(@"Moving button"); [self.view removeConstraint:self.hConstraint]; [self.view removeConstraint:self.vConstraint]; [UIButton beginAnimations:nil context:nil]; [UIButton setAnimationDuration:0.3]; _addMoreFieldsBtn.center = CGPointMake(30,30); [UIButton commitAnimations]; }
(the actual view that you need to call removeConstraints: on is the parent view of the button, which may or may not be self.view).
source share