iOS侧滑返回上一级界面
2015-09-28 14:47
417 查看
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super
initWithRootViewController:rootViewController];
if (self) {
id target =
self.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer
alloc] initWithTarget:target
action:@selector(handleNavigationTransition:)];
//
设置手势代理,拦截手势触发
pan.delegate =
self;
[self.view
addGestureRecognizer:pan];
//
禁止使用系统自带的滑动手势
self.interactivePopGestureRecognizer.enabled =
NO;
}
return
self;
}
// 什么时候调用:每次触发手势之前都会询问下代理,是否触发。
// 作用:拦截手势触发
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (_stopBack ==
YES) {//是否允许返回
return NO;
}
//
注意:只有非根控制器才有滑动返回功能,根控制器没有。
//
判断导航控制器是否只有一个子控制器,如果只有一个子控制器,肯定是根控制器
if (self.
childViewControllers.count == 1) {
//
表示用户在根控制器界面,就不需要触发滑动手势,
return NO;
}
return
YES;
}
{
self = [super
initWithRootViewController:rootViewController];
if (self) {
id target =
self.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer
alloc] initWithTarget:target
action:@selector(handleNavigationTransition:)];
//
设置手势代理,拦截手势触发
pan.delegate =
self;
[self.view
addGestureRecognizer:pan];
//
禁止使用系统自带的滑动手势
self.interactivePopGestureRecognizer.enabled =
NO;
}
return
self;
}
// 什么时候调用:每次触发手势之前都会询问下代理,是否触发。
// 作用:拦截手势触发
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (_stopBack ==
YES) {//是否允许返回
return NO;
}
//
注意:只有非根控制器才有滑动返回功能,根控制器没有。
//
判断导航控制器是否只有一个子控制器,如果只有一个子控制器,肯定是根控制器
if (self.
childViewControllers.count == 1) {
//
表示用户在根控制器界面,就不需要触发滑动手势,
return NO;
}
return
YES;
}
相关文章推荐
- iOS开发日记26-详解时间戳
- [iOS学习]函数的定义,函数的调用以及函数的声明
- iOS绘图教程
- iOS本地的缓存的方式
- Error:IOS集成支付宝出现的错误
- iOS开发引入第三方类库的问题
- iOS应用之地图
- ios 里如何判断当前应用的定位服务是否可用
- iOS8 【xcode6中添加pch全局引用文件】
- 关于真机测试证书的申请
- ios去掉navigationController和tabBarController里的边框黑线
- iostat分析磁盘的IO状况
- iOS9适配
- iOS蓝牙4.0
- IOS开发—对当前屏幕闲置时间计时
- iOS上如何让按钮文本左对齐问题
- Nagios
- 实现iOS全局禁止横屏,但kxmovie全屏横屏播放视频
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- ios模拟器不响应电脑键盘解决方法