sridvijay
sridvijay

Reputation: 1526

UIView Animation doesn't fire when called from different view controller?

I'm calling a method from another view controller by using this:

   InitialViewController *secondController = [[InitialViewController alloc] init];
   [secondController forecast];

Here's the method in the InitialViewController:

-(void)forecast{
    [UIView beginAnimations:@"Forecast" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0f];
    self.customPager.frame = CGRectMake(0,5, 320, 510);
    self.view1.frame = CGRectMake(-320,5, 320, 510);
    radarView.frame = CGRectMake(0,560, 320, 510);
    [UIView commitAnimations];
    NSLog(@"Method Passed");
}

In my console, I get the NSLog "Method Passed", but the UIView animation does not occur at all. Any ideas?

Upvotes: 0

Views: 221

Answers (3)

sergio
sergio

Reputation: 69027

It seems to me that you are not displaying in any way the view associated to secondController. I.e., after doing:

InitialViewController *secondController = [[InitialViewController alloc] init];

I would expect you do something like:

[self.view addSubview:secondController.view];

This would trigger loadView/viewDidLoad before you call forecast. Furthermore, I would give a chance to the UI to be show your view before animating it; thus, I would call forecast either like this:

[self performSelector:@selector(forecast) withObject:nil afterDelay:0.0];

or from viewDidAppear.

EDIT:

According to your comment, your InitialViewController is already displayed on screen. In this case, what you should do is getting a reference to it and sending it the forecast message.

What you are doing now is instantiating a new InitialViewController (and then sending the forecast message to it) that has no relation with the one already displayed.

Upvotes: 2

rdelmar
rdelmar

Reputation: 104082

If your second controller is already on the screen, then your alloc init is creating another one, not getting the one already present (the log works because you are creating an instance of InitialViewController, so its code will run, but another instance's view is the one you're seeing on screen). You need to get a reference to the one on screen. I can't say how you should do that without knowing how you got your 2 controllers on the screen in the first place.

Upvotes: 0

omz
omz

Reputation: 53551

Even though you instantiate secondController, its view is never displayed on screen, or even loaded, so any animations that you apply to it have no effect.

Upvotes: 1

Related Questions