iOS手势滑动返回效果

2017-08-18  本文已影响0人  JHAO_浮夸
开发中有时需求会要求滑动控制器直接返回 ,苹果自带效果只能在控制器的边缘处返回 现分享一种比较优雅的处理方法:
   //找到原有的手势对象及实现方法 self.interactivePopGestureRecognizer.delegate\handleNavigationTransition

      UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
      pan.delegate=self;
    self.interactivePopGestureRecognizer.enabled=NO;
    //给导航控制的View添加拖拽手势
     [self.view addGestureRecognizer:pan];
    

   }


- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
   //回到首页控制器时不用开启手势
    return !(self.childViewControllers.count==1);
 
}
滑动返回.gif
上一篇下一篇

猜你喜欢

热点阅读