>我有一个非常奇怪的问题,在典型的动画过渡代码中,如下所示,在进行几次过渡后,视图变得无响应。我挖了一点,发现没有调用navigationController:animationControllerForOperation:fromViewController:toViewController:
方法,甚至调用了pushViewController:animated:
方法。有什么想法吗?
此 VC 将传输到另一个 VC,然后该 VC 可以通过交互式动画过渡传输回来。同样的问题也发生在另一个视图中,即启动了转换,但没有调用navigationController:animationControllerForOperation:fromViewController:toViewController:
。这只会在我玩了大约半分钟的应用程序之后发生。
.h file
@interface ViewController : UIViewController <UINavigationControllerDelegate>
@end
.m file
@implementation ViewController
- (void)viewDidAppear:(BOOL)animated
{
[self.navigationController setDelegate:self];
}
- (void) transit_to_next_view
{
//...
UIViewController* newvc;
[self.navigationController pushViewController:newvc animated:YES];
}
// animated transition
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
// return animator
}
@end
事实证明,我错误地在toViewController的viewDidLoad函数中向导航控制器添加了一个平移识别器。即使转换被取消,平移识别器仍处于活动状态,并将所有平移手势路由到已取消的 ViewController,而不是可见的 fromViewController。因此,不会触发 fromViewController 中的平移识别器,并且转换永远不会再次发生。将平移识别器从 toViewController 的 viewDidLoad 函数移动到其 viewDidAppear 函数解决了该问题。