想实现全屏滑动返回时可以使用FDFullscreenPopGesture,传送门https://github.com/forkingdog/FDFullscreenPopGesture
下面介绍一下FDFullscreenPopGesture的简单使用
界面效果如下
首先将文件加入工程,对于有Navigation Bar的不用做任何修改就能支持全屏滑动返回,如
如果没有Navigation Bar需要添加如下代码
#pragma mark - life cycle
- (void)viewDidLoad
{
[super viewDidLoad];
// 隐藏 Navigation Bar
self.fd_prefersNavigationBarHidden = YES;
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.myBtn];
self.myBtn.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 200) / 2.0, 200, 200, 40);
}
效果如下
如果页面中有scrollView需要添加如下代码
@implementation UIScrollView (DMFullScreen)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (self.contentOffset.x <= 0) {
if ([otherGestureRecognizer.delegate isKindOfClass:NSClassFromString(@"_FDFullscreenPopGestureRecognizerDelegate")]) {
return YES;
}
}
return NO;
}
@end
效果如下
如果想在页面中禁用全屏滑动返回,需要添加如下代码
#pragma mark - life cycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"禁止全屏滑动返回";
self.view.backgroundColor = [UIColor whiteColor];
// 禁止滑动返回
self.fd_interactivePopDisabled = YES;
[self.view addSubview:self.systemLabel];
self.systemLabel.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 220) / 2, 100, 220, 30);
[self.view addSubview:self.customLabel];
self.customLabel.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 220) / 2, 200, 220, 30);
[self.view addSubview:self.qrCodeImgView];
self.qrCodeImgView.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 129) / 2, 240, 129, 129);
}
效果如下
FDFullscreenPopGesture 的实现原理可以参考这篇文章(传送门http://blog.sunnyxx.com/2015/06/07/fullscreen-pop-gesture/
)以及这篇文章(传送门http://www.jianshu.com/p/d39f7d22db6c )。
全屏滑动返回的示例就结束啦...