1.解决自定义返回按钮边缘滑动失效的问题
(1)自定义了导航控制器 重写 pushViewController 方法自定义了返回按钮 边缘滑动失效
(2)在 viewDidLoad 设置()
//边缘滑动
self.interactivePopGestureRecognizer.delegate =self;
(3)设置代理实现方法(因为不设置在根控制器会触发手势,造成假死状态)
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return self.childViewControllers.count>1;
}
2.实现全屏滑动返回效果
(1)自定义了导航控制器 重写 pushViewController 方法自定义了返回按钮 边缘滑动失效
(2)在 viewDidLoad 设置(遵守协议)
//全屏滑动
//添加新的拖拽手势 调用系统原来的滑动方法
(方法由来请打印self.interactivePopGestureRecognizer)
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizeralloc]initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
pan.delegate =self;
[self.viewaddGestureRecognizer:pan];
//禁止原来自带的手势
self.interactivePopGestureRecognizer.enabled =NO;
(3)设置代理实现方法(因为不设置在根控制器会触发手势,造成假死状态)
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return self.childViewControllers.count>1;
}
3.如果子控制存在水平方向滚动的ScrollView时(边缘返回)手势失效 解决办法//多手势共同触发
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
//以下两个成对的方法比较有趣(实现其一即可)
//返回yes-前面失效后面生效 返回no-前面生效后面失效
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return ![gestureRecognizerisKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}
//返回yes-前面生效后面失效 返回no-前面失效后面生效
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return [gestureRecognizerisKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}
4.如果子控制存在水平方向滚动的ScrollView时(全屏返回)(个人观点 不喜勿喷,欢迎指正)(实现 多手势共同触发代理 会导致ScrollView的左拖拽和滑动返回冲突)
建议:如果子控制要实现scrollview 的水平滑动 建议实现边缘滑动
如果要是实现全屏滑动返回 建议不使用scrollview的水平滑动,建议使用按钮的点击切换(详情效果请看qq全屏返回 兴趣部落模块 实现
(1)自己加的全屏拖拽手势<UIPanGestureRecognizer: 0x147df0ab0; state = Possible; view = <UILayoutContainerView 0x147dec780>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x147defa40>)>>
(2)UIScrollView 的手势<UIScrollViewPanGestureRecognizer: 0x1491d5670; state = Possible; delaysTouchesEnded = NO; view = <UICollectionView 0x1481e9a00>; target= <(action=handlePan:, target=<UICollectionView 0x1481e9a00>)>; must-fail = {
<UIScrollViewPagingSwipeGestureRecognizer: 0x149101620; state = Failed; view = <UICollectionView 0x1481e9a00>; target= <(action=_handleSwipe:, target=<UICollectionView 0x1481e9a00>)>>