UINavigationControllerDelegate
只能使用2种委派方法:
navigationController:willShowViewController:
navigationController:didShowViewController:
但是当我使用手势以交互方式弹出viewController时我想要被调用怎么办?类似的东西:
navigationController:willStartDragging:
navigationController:isDraggingWithPercentage:
协议中没有这样的委托方法。我怎样才能获得这些方法?
答案 0 :(得分:1)
您可以将目标/操作添加到导航控制器的interactivePopGestureRecognizer
,如下所示:
[navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handleInteractivePop:)];
然后跟踪手势的状态
- (void)handleInteractivePop:(UIScreenEdgePanGestureRecognizer *)recognizer {
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:
// Started Dragging
break;
case UIGestureRecognizerStateChanged:
CGFloat percentComplete = [recognizer locationInView:yourView].x / yourView.frame.size.width;
// Do something
break;
case UIGestureRecognizerStateEnded:
// Released
break;
default:
break;
}
}