0

So I have a button with an IBAction which is supposed to display a subview. The view is in the storyboard and I'm calling it was instantiateViewController. This works fine. I would like to animate the views transition onto the screen which is where I hit this problem. The following code is what I have however all it does is display the entire view at once but without text on buttons etc. and then drags the text down from the top. Quite obscure. Commenting out the setAnimationTransition line heralds the same result.

MapViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MapViewController"];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:MapViewController.view cache:YES];

[self.view addSubview:MapViewController.view];
[UIView commitAnimations];

Anybody have any ideas?

Your help is much appreciated.

Thanks.

As per the comment below I have changed it to:

[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{[self.view addSubview:MapViewController.view];} completion:NULL]; 

However the problem still persists.

Compy
  • 1,157
  • 1
  • 12
  • 24
  • [Remember these:](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/) _Use of the methods in this section is discouraged in iOS 4 and later. Use the block-based animation methods instead._ – Alex Salom Jun 19 '13 at 11:43
  • Ok, so I changed it to: [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{[self.view addSubview:MapViewController.view];} completion:NULL]; however I still have the same problem. – Compy Jun 19 '13 at 12:12
  • What are you trying to do? Animated the adding of a scene to a custom container (in which case you need containment calls, `addChildViewController` and `didMoveToParentViewController`). Or are you trying to transition to another scene, in which case you should either `presentViewController` or `pushViewController`). We can't help you on your animation until we understand what you're trying to do. – Rob Jun 19 '13 at 12:14
  • 1
    @Adam look at this question, exactly the same wanted behaviour. http://stackoverflow.com/a/8561946/342437 . The answer by adedoy is the one you are after. – mbogh Jun 19 '13 at 12:31
  • @mbogh Thanks! Unbelievably I tried that one earlier and found it not to work. I must have done something different this time as it now works. Thanks very much! – Compy Jun 19 '13 at 12:42

3 Answers3

1

Try this :

[UIView transitionWithView:self.view
                duration:0.5
                options:UIViewAnimationOptionTransitionFlipFromRight
                animations:^{
                   [self.view addSubview:MapViewController.view];
                }
                completion:nil];
Geek
  • 8,280
  • 17
  • 73
  • 137
1
[UIView transitionWithView:containerView duration:0.5
    options:UIViewAnimationOptionTransitionCurlUp //change to whatever animation you like
    animations:^ { [containerView addSubview:subview]; }
    completion:nil];

Seemed to work.

Compy
  • 1,157
  • 1
  • 12
  • 24
0

Change

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                       forView:MapViewController.view 
                         cache:YES];

to

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                       forView:self.view 
                         cache:YES];

You are not animating the view you add, you animate the container...

Also note that this set of methods is deprecated and if you are not targetting iOS < 4.0, you should use the block-based animation methods instead.

Don't use UIViewAnimationOptionTransitionFlipFromRight, that's only for the block-based methods (see Akash's answer).

Sulthan
  • 128,090
  • 22
  • 218
  • 270