调用-[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]
时,我会得到一个奇怪的导航栏动画。我之前肯定已经看到了这样的事情,在动画期间将视图添加到屏幕,并且因为它没有从0,0开始的动画框架。但我不确定导航栏中是什么导致它。
用于转换视图控制器的代码:
- (void)setCurrentViewController:(UIViewController<TCSearchResultsViewController> *)currentViewController animated:(BOOL)animated
{
[self.searchBar resignFirstResponder];
if (_currentViewController != currentViewController) {
if (_transitioning) {
__weak __typeof(self)self_weak = self;
_afterTransition = ^{
[self_weak setCurrentViewController:currentViewController animated:animated];
};
return;
}
UIViewController<TCSearchResultsViewController> *oldViewController = _currentViewController;
_currentViewController = currentViewController;
[oldViewController willMoveToParentViewController:nil];
[self addChildViewController:_currentViewController];
_currentViewController.view.frame = self.resultsViewContainer.bounds;
_currentViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_currentViewController.groups = _searchManager.allObjects;
_currentViewController.location = _location;
if (oldViewController != nil) {
_transitioning = YES;
[self transitionFromViewController:oldViewController
toViewController:_currentViewController
duration:(animated ? 0.5 : 0.0)
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil completion:^(BOOL finished) {
[_currentViewController didMoveToParentViewController:self];
// this will make sure UITableViewController catches up to the keyboard position
UIView *firstResponder = self.view.window.firstResponder;
if (firstResponder != nil) {
[firstResponder resignFirstResponder];
[firstResponder becomeFirstResponder];
}
_transitioning = NO;
if (_afterTransition != nil) {
_afterTransition();
_afterTransition = nil;
}
}];
} else {
[self addViewController:self.listViewController toView:self.resultsViewContainer];
_transitioning = NO;
if (_afterTransition != nil) {
_afterTransition();
_afterTransition = nil;
}
}
}
}
以下是有关它的视频:http://f.cl.ly/items/2s0H0n3g3i0C1K470V2V/Nav%20Bar%20Animation.mov
正在转换的视图控制器位于视频中的双线下方。