今天要介紹的是一種最簡單的返回方式:看下圖
@interface UIViewController ()<UIGestureRecognizerDelegate>
id target = self.navigationController.interactivePopGestureRecognizer.delegate;
// handleNavigationTransition:為系統(tǒng)私有API,即系統(tǒng)自帶側(cè)滑手勢的回調(diào)方法徙赢,我們在自己的手勢上直接用它的回調(diào)方法
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
panGesture.delegate = self; // 設(shè)置手勢代理汉形,攔截手勢觸發(fā)
[self.view addGestureRecognizer:panGesture];
// 一定要禁止系統(tǒng)自帶的滑動(dòng)手勢
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
最后:
// 什么時(shí)候調(diào)用洛波,每次觸發(fā)手勢之前都會(huì)詢問下代理方法梁只,是否觸發(fā)
// 作用:攔截手勢觸發(fā)
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
// 當(dāng)當(dāng)前控制器是根控制器時(shí),不可以側(cè)滑返回,所以不能使其觸發(fā)手勢
if(self.navigationController.childViewControllers.count == 1)
{
return NO;
}
return YES;
}
- (void)handleNavigationTransition:(UIGestureRecognizer *)ges{
}