If you've tried animating a UIView onto the screen using UIViewAnimationTransitionFlipFromLeft or UIViewAnimationTransitionFlipFromRight you may have noticed a slight lag in the first animation. The obvious way to implement a flip transition is with code like the following:
- (void)showFlipView {
UIView *parentView = self.view;
self.flipViewController.view.frame = parentView.bounds;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:parentView
cache:YES];
[UIView setAnimationDuration:1];
[parentView addSubview:self.flipViewController.view];
[UIView commitAnimations];
}
One explanation for the lag you sometimes see is that views are lazy loaded, and the delay is caused by the flip view being loaded. But even if you force the view to be loaded by accessing the controller's view property this lag can still manifest.
One way I found to stop this lag is to add the flip view to the parent view when the parent view loads, and set its hidden value to YES. Then when you want to animate it in, you set hidden to NO:
- (void)viewDidLoad {
[super viewDidLoad];
// ...
self.flipViewController.view.hidden = YES;
[self.view addSubview:self.flipViewController.view];
}
- (void)showFlipView {
UIView *parentView = self.view;
self.flipViewController.view.frame = parentView.bounds;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:parentView
cache:YES];
[UIView setAnimationDuration:1];
self.flipViewController.view.hidden = NO;
[UIView commitAnimations];
}
![Email me [email address]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ_JhGL8XPx4ja4vtcBNqkgtWhsuFo6Hkr6_TBo3bTjfbu6yskRgIRz57JZ7zU2K7MNDuSfkugZq4CGkDuv5ZPKqYNwT3TlxU7jVXuxut-hxo58QzMeHipfm9tuz1S0HOlLYMVjbi9rpA/s400/email.png)