标签:
看到现在app 中越来越流行的手势滑动实现pop效果,心里很是痒痒跃跃欲试,经过多方查看资料,终于在简书上找到了详细的实现方案:
经过修改实现了简单的(自定义导航控制器)手势滑动实现pop返回效果:
1.先打印了导航控制器的interactivePopGestureRecognizer,log结果如下:
<UIScreenEdgePanGestureRecognizer: 0x7fe5f1579ce0; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7fe5f1567ea0>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition
2.自定义UIPanGestureRecognizer,移花接木到该手势的target和action;action好处理,但是target的活得用runtime时可以拿到,但过程略复杂,
打印interactivePopGestureRecognizer.delegate;发现正好也是_UINavigationInteractiveTransition,所以问题解决:
id target = self.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:NSSelectorFromString(@"handleNavigationTransition:")];
3.测试发现如果当前导航控制器的自控制器只有一个的时候,拖拽手势会发生bug,这时就需要腹泻pan手势的
-(BOOL)gestureRecognizerShouldBegin:来决定手势操作是否起作用:
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return self.childViewControllers.count==1?NO :YES;
}
4.附上github上forkingdog的更加完美的分类实现方法:
https://github.com/forkingdog/UITableView-FDTemplateLayoutCell
TIP:相关bug小提示,如果自定了导航控制器的自控制器的leftBarButtonItem,可能会引发边缘滑动pop效果的失灵,是由于
self.interactivePopGestureRecognizer.delegate被滞空的原因
标签:
原文地址:http://www.cnblogs.com/shuizhuqing/p/4726010.html