如果滑动移除控制器的功能失效,清空代理(让导航控制器重新设置这个功能)
self.interactivePopGestureRecognizer.delegate=nil;
//RLNavigaitionController.m
//RLNavigaitionDemo
//Created 16/7/3.
//Copyright © 2016年. All rights reserved.
#import"RLNavigaitionController.h"
@interfaceRLNavigaitionController()
@property(nonatomic,strong)NSMutableArray*images;
@property(nonatomic,strong)UIImageView*screenView;
@property(nonatomic,strong)UIView*coverView;
@end
@implementationRLNavigaitionController
- (void)viewDidLoad {
[superviewDidLoad];
UIPanGestureRecognizer*gesture = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(panBack:)];
[self.viewaddGestureRecognizer:gesture];
}
-(void)viewDidAppear:(BOOL)animated
{
if(self.images.count>0)return;
[selfscreenSnapShot];
}
-(void)screenSnapShot
{
UIGraphicsBeginImageContextWithOptions(self.view.frame.size,NO,1);
CGContextRefcontext =UIGraphicsGetCurrentContext();
[self.view.layerrenderInContext:context];
UIImage*image =UIGraphicsGetImageFromCurrentImageContext();
[self.imagesaddObject:image];
UIGraphicsEndImageContext();
}
-(void)pushViewController:(UIViewController*)viewController animated:(BOOL)animated
{
[superpushViewController:viewControlleranimated:animated];
[selfscreenSnapShot];
}
-(UIViewController*)popViewControllerAnimated:(BOOL)animated
{
[self.imagesremoveLastObject];
return[superpopViewControllerAnimated:animated];
}
-(void)panBack:(UIPanGestureRecognizer*)gesture
{
CGFloattranslationx = [gesturetranslationInView:self.view].x;
if(translationx <0||self.images.count<2)return;
self.screenView.image=self.images[self.images.count-2];
UIWindow*window = [UIApplicationsharedApplication].keyWindow;
[windowinsertSubview:self.screenViewatIndex:0];
[windowinsertSubview:self.coverViewaboveSubview:_screenView];
gesture.view.transform=CGAffineTransformMakeTranslation(translationx,0);
if(gesture.state==UIGestureRecognizerStateEnded|| gesture.state==UIGestureRecognizerStateCancelled) {
gesture.view.transform=CGAffineTransformIdentity;
if(translationx >self.view.frame.size.width*0.5) {
[selfpopViewControllerAnimated:NO];
[self.screenViewremoveFromSuperview];
[self.coverViewremoveFromSuperview];
}
}
}
-(NSMutableArray*)images
{
if(!_images) {
_images= [NSMutableArrayarray];
}
return_images;
}
-(UIImageView*)screenView
{
if(!_screenView) {
_screenView= [[UIImageViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
}
return_screenView;
}
-(UIView*)coverView
{
if(!_coverView) {
_coverView= [[UIViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
_coverView.backgroundColor= [UIColorcolorWithRed:0.5green:0.5blue:0.5alpha:0.5];
}
return_coverView;
}
@end