我知道這是舊的,但對於任何其他可能面臨類似問題的人。這是我使用的方法。首先,我向我的導航控制器註冊一個UINavigationControllerDelegate
。代表需要執行。
Objective-C的
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
斯威夫特
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool)
所以實施將是這個樣子。
Objective-C的
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
id<UIViewControllerTransitionCoordinator> tc = navigationController.topViewController.transitionCoordinator;
[tc notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) {
NSLog(@"Is cancelled: %i", [context isCancelled]);
}];
}
斯威夫特
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
if let coordinator = navigationController.topViewController?.transitionCoordinator() {
coordinator.notifyWhenInteractionEndsUsingBlock({ (context) in
print("Is cancelled: \(context.isCancelled())")
})
}
}
回調當用戶舉起她的手指和(Objec-C)[context isCancelled];
(雨燕)將觸發context.isCancelled()
將返回YES
/true
如果動畫被反轉(視圖控制器未被彈出),否則NO
/false
。 context
中有更多的東西可以使用,比如兩個視圖控制器都包含在內,以及發佈後完成的動畫的百分比等。
有趣的問題。我有一種感覺,你需要禁用'interactivePopGestureRecognizer'並註冊你自己的或使用iOS 7的[交互式轉換](http://www.objc.io/issue-5/view-controller-transitions.html) –
我擔心你可能是對的。似乎很奇怪,這不是一個常見問題。我希望至少在某些時候,至少有一些應用需要實現這一點。關於實現自定義轉換的最糟糕的事情是,您必須明確禁用每個控制器上的手勢,並在彈出(或另一個控制器被按下)後重新啓用它。 –