Hello,
I'm using this code after in my ViewDidLoad method :
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
self.view.frame = CGRectMake(0, 0, 250, 50);
[UIView commitAnimations];
It's working fine but if I try to do the same thing in an other method in the same implementation file like this :
- (void)setViewMovedUp:(BOOL)movedUp {
NSLog(@"test movedUp ");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
self.view.frame = CGRectMake(0, 0, 250, 50);
[UIView commitAnimations];
}
Then the animation doesn`t work anymore ( but the NSLog still prints ) . Why would this method behave differently than after "viewDidLoad" ? The setViewMovedUp is called after a button is pressed, therefore I assume that the view is already loaded ? Should I add a condition to make sure that the view is loaded then ?
Edit after Michal's comment :
The button I press uses this IBAction in MyViewController.m :
- (IBAction)viewUp {
MainViewController *moveUp = [[MainViewController alloc] init];
[moveUp setViewMovedUp:YES];
}
and this is the code in MainViewController.m :
- (void)setViewMovedUp:(BOOL)movedUp {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
self.view.frame = CGRectMake(0, 0, 250, 250);
[UIView commitAnimations];
}
The Button's IBAction is not communicating well with the MainViewController method (setViewMovedUp) .
In you example it's working well in the same class .