Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8747293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:19:58+00:00 2026-06-13T12:19:58+00:00

So I am trying to move a UIButton after it is clicked. The _addMoreFields

  • 0

So I am trying to move a UIButton after it is clicked.

The _addMoreFields method is called after the button is clicked.

_addMoreFieldBtn is a global UIButton. When I click it nothing happens.

The strange part is if I comment out the addSubView code then the button moves.

If I keep that code the button doesn’t move.

Any Ideas?

-(void)movePlusButton {
    NSLog(@"Moving button");
    [UIButton beginAnimations:nil context:nil];
    [UIButton setAnimationDuration:0.3];
    _addMoreFieldsBtn.center = CGPointMake(30,30);
    [UIButton commitAnimations];
}

- (IBAction)addMoreFields:(id)sender {

    CGRect currentBtnFrame = [(UIButton *)sender frame];
    CGPoint org = currentBtnFrame.origin;

    UILabel *whoWasIn = [[UILabel alloc]  initWithFrame:CGRectMake(110, org.y, 85, 21)];
    whoWasIn.text = @"test";

    UITextField *whoWasInField = [[UITextField alloc] initWithFrame:CGRectMake(59, whoWasIn.frame.origin.y+40, 202, 30)];
    whoWasInField.placeholder = @"test2";

    UILabel *with = [[UILabel alloc]  initWithFrame:CGRectMake(136, whoWasInField.frame.origin.y+40, 49, 21)];
    with.text = @"with";
    whoWasInField.borderStyle = UITextBorderStyleRoundedRect;

    UITextField *withField = [[UITextField alloc] initWithFrame:CGRectMake(59, with.frame.origin.y+40, 202, 30)];
    withField.placeholder = @"test3";
    withField.borderStyle = UITextBorderStyleRoundedRect;

    [_homeView addSubview:whoWasIn];
    [_homeView addSubview:with];
    [_homeView addSubview:whoWasInField];
    [_homeView addSubview:withField];

    [self movePlusButton];
}

NOTE: I also tried changing the frame but I get the same issue. It starts animating from the new location I put to the existing spot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:19:59+00:00Added an answer on June 13, 2026 at 12:19 pm

    The issue is that new projects in iOS 6 / Xcode 4.5 have “Autolayout” enabled by default. Autolayout is a replacement for “Springs and Struts” (but it only works iOS 6). This feature adds constraints to a view which take precedence over the move you were attempting in your code.

    So there are three possible fixes to this:

    1) Create new constraints on the button programmatically. Autolayout is pretty powerful and flexible… especially if you are trying to support the footprint of both the iPhone 5 and earlier models. You can find more info on how to do this by checking out the WWDC video: Introduction to Auto Layout for iOS and OS X

    2) Don’t use Autolayout. Select a view in your Storyboard, and in the File Inspector, uncheck “Use Autolayout.”

    3) Create IBOutlets for each of the constraints on the button. Then before you move the button, remove those constraints:

    @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 you need to call removeConstraints: on is the parent view of the button, which may or may not be self.view).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to animate a UIButton to move randomly around the screen in different
I'm trying to animate a UIButton to move up the screen. At any point
I'm trying to have a button move to a co-ordinates, pause, move to another
I'm trying to move (File.Move) locked .dll file to perform application update. File.Move method
I'm trying to move a div by clicking a button and have an alert
Trying to move some divs using hover, this is my markup: <div class=item dark-grey>
I am trying to move some files in python, but they have spaces in
I am trying to move even numbers in an array to the front and
I am trying to move an object by checking if the mouse is colliding
I am trying to move the logic to the very high-level from the db.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.