Question

I am doing a simple call to a method with animation in viewDidApepar in my app, the initial position of the view that is being animated in the storyboard is (10 , 5) - almost hidden from the main view.

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self doTheAnimation];    
}

and the method contains

[UIView animateWithDuration:0.8f delay:0.0f usingSpringWithDamping:0.5f initialSpringVelocity:1.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
     [plotView setFrame:CGRectMake(10, 40, 299, 130)];
} completion:nil];

The Problem: When the application is started - all works great with a cool "spring" effect, but when I push to another view and go back to the main view, the method with animation is called, the LOG shows that the plotView had changed frame.origin to (10,40) but it is still staying stuck at (10,5) its initial position on the storyBoard.

Was it helpful?

Solution

Replace

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self doTheAnimation];    
}

with

-(void) viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [self doTheAnimation];    
}

OTHER TIPS

Don't change the place of your method, just add this :

[plotView setFrame:CGRectMake(10, 5, 299, 130)];
[UIView animateWithDuration:0.8f delay:0.0f usingSpringWithDamping:0.5f initialSpringVelocity:1.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    [plotView setFrame:CGRectMake(10, 40, 299, 130)];
} completion:^{
    [plotView setFrame:CGRectMake(10, 40, 299, 130)];
}];

Tell me if it works :)

Better is:

[self performSelector:@selector(doTheAnimation) withObject:nil afterDelay:0.5];

Set the delay as you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top