title: UIView transitionFromView: toView: animation not working.
body: <p>It's my first post on stackoverflow. I'm a iOS developer newbie and I'm not a native English speaker, so I will do my best to explain my problem. </p>
  
  <p><strong>Problem:</strong></p>
  
  <p>I have added two views to my AppDelegate window and I want to flip from one to the other using:</p>
  
  <pre><code> UIView transitionFromView:toView:
  </code></pre>
  
  <p>The first view (MainScreenView) has its own <code>ViewController</code>. On the MainScreenView .xib file I have a button with an action that calls the method "goShow" implemented in my AppDelegate. In that method I use <code>UIView transitionFromView:toView:</code> to transition to the second view. So far everything is working fine.
  My second view (a scrollview) is declared programmatically in my AppDelegate and has a bunch of pictures inside it (picturesViewController) and on top of those, has a <code>UIPinchGestureRecognizer</code>.</p>
  
  <p>I'm using a gesture recognizer to flip back to my MainScreenView. That is where the problem is. When I do a pinch gesture on the scrollview the <code>MainScreenView.view</code> appears immediately, before the animation, so the flip animation looks wrong. </p>
  
  <p>The code I'm using is:</p>
  
  <pre><code>-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
  
  mainScreen = [[MainScreenViewController alloc] initWithNibName:@"MainScreenViewController" bundle: [NSBundle mainBundle]];
  
  CGRect frame = self.window.bounds;
  int pageCount = 10;
  scrollView = [[UIScrollView alloc] initWithFrame:frame];
  scrollView.contentSize = CGSizeMake(320*pageCount, 480);
  scrollView.pagingEnabled = YES;
  scrollView.showsHorizontalScrollIndicator = FALSE;
  scrollView.showsVerticalScrollIndicator = FALSE;
  scrollView.delegate = self;
  
  [...] 'While' adding pictures to de scrollView
  
  UIPinchGestureRecognizer *twoFingerPinch = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(goBackToMain)] autorelease];
  [scrollView addGestureRecognizer:twoFingerPinch];
  
  [self.window addSubview: scrollView];
  [scrollView setHidden:TRUE];
  [self.window addSubview: mainScreen.view];
  
  [self.window makeKeyAndVisible];
  return YES;
  }
  
  -(void) goShow{
  
  [UIView transitionFromView:mainScreen.view
                      toView:scrollView 
                    duration:0.5
                     options:UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionShowHideTransitionViews                    
                  completion:NULL];
  
  [UIView commitAnimations];    
  }
  
  -(void) goBackToMain {
  
  [UIView transitionFromView:scrollView
                      toView:mainScreen.view 
                    duration:0.5
                     options:UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionShowHideTransitionViews                     
                  completion:NULL]; 
  
  [UIView commitAnimations];
  }
  </code></pre>
  
  <p>I'm using show/hide views instead of <code>addSubview/removeFromSuperView</code> because I tried the add and remove and got an app crash in the pinch gesture, exactly in same step that is failing the animation. Probably it is the same error, but I'm unable to find the reason for this. Any help would be appreciated. </p>
  
  <p>Thanks.</p>
  
  <p>Ok. With Adrian's help, here's the UIPinchGesture code that solved my problem:</p>
  
  <pre><code>[...]
  
  UIPinchGestureRecognizer *twoFingerPinch = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(goBackToMain:)] autorelease];
  [scrollView addGestureRecognizer:twoFingerPinch];
  
  
  -(void)goBackToMain:(UIPinchGestureRecognizer *)recognizer {
  
  if (recognizer.state == UIGestureRecognizerStateEnded)
  {
      [UIView transitionFromView:scrollView
                          toView:mainScreen.view 
                        duration:0.4
                         options:UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionShowHideTransitionViews                     
                      completion:nil]; 
  
      [UIView commitAnimations];
  }
  </code></pre>