1

I have a UIView that I am trying to move up bit when that parent view controller comes onto the screen. I have been reading up on this and most I see seem to say to use the viewDidAppear method to make any visual adjustments to the layout. I have tried this and it doesn't seem to work. Nothing happens, and went I nslog the origin.y I get back -47,000, which I then maybe assume that something is not initialized yet. Here is what I have tried.

  - (void) viewDidAppear:(BOOL)animated
    {
        // set the save view y postion
       saveData.center = CGPointMake( 0.0f, 0.5f );
        NSLog(@"This is the y %f", saveData.frame.origin.y);
        NSLog(@"This is the center points on load %@", NSStringFromCGPoint(optionalData.center));
    }

But if I do something like this where I add a delayed method call in the viewDidLoad method:

[self performSelector:@selector(moveSaveView) withObject:nil afterDelay:0.7f];

and have this, it works

- (void) moveSaveView
{
    // set the save buttons y postion


    [UIView animateWithDuration:0.5 delay:0.0 options:0 animations:^{
        // Animate the alpha value of your imageView from 1.0 to 0.0 here
        optionalData.alpha = 0.0f;
    } completion:^(BOOL finished) {
        // Once the animation is completed and the alpha has gone to 0.0, hide the view for good
        optionalData.hidden = YES;
    }];

    // move the save button up
    [UIView animateWithDuration:0.5
                     animations:^{saveData.center = CGPointMake( 160.0f, 280.5f );}];


    saveData.center = CGPointMake( 160.0f, 280.5f );
}

Is this also an issue due to the fact that I am using auto layout? I would just like my view to start in the place I need it to, and not use some delayed call to make that happen.

Edit: So I gave this a shot and came up with this to try and move my UIView:

- (void) viewDidAppear:(BOOL)animated
    {   
        NSLog(@"this is the constraing %f",     saveData.saveButtomConstraint.constant);  // gives me 93 which is here its at.
        saveData.saveButtomConstraint.constant = 32;
        [saveData setNeedsUpdateConstraints];
        [saveData layoutIfNeeded];
        NSLog(@"this is the constraing %f", saveData.saveButtomConstraint.constant); // gives me 32 which is here its at.   
    }

The problem is that the view never moves on the screen. What am I missing? Also is it ok to post and edit like this, when its related to the same question? I'm still trying to get the hang of this form.

tshepang
  • 12,111
  • 21
  • 91
  • 136
icekomo
  • 9,328
  • 7
  • 31
  • 59

1 Answers1

1

Yes, your problem is due to the fact you are using auto layout. Frame animation is not compatible with auto layout, so instead you need to animate the constraints on your view. Check out this answer for detailed info, this might also help too. Good luck!

Edit:

So it looks like you have added a property to your saveData UIView called saveButtomConstraint. This is good as it gives you access to that constraint. However are you sure that that constraint is actually a member of the [saveData constraints] array? Generally constraints in Interface Builder are added to the parent UIView. I think the problem is most likely are calling layoutIfNeeded on the wrong view, you need to call it on parent view of saveData, or possibly on the root view of the view controller, [self view].

Community
  • 1
  • 1
BTSmith
  • 600
  • 4
  • 7