/**
Just change to the following code in your custom navigation controller, and the custom gesture returns
*/
#define Key_window [[UIApplication sharedapplication] Keywindow]
#define KSCREENW KEY_WINDOW.bounds.size.width
#define Kanimateduration 0.3
#define KDEFAULTALAPA 0.5
#define Kdefaultscale 0.95
#define IOS7 ([Uidevice currentdevice].systemversion.floatvalue >= 7.0)
#import "CXNavigationController.h"
#import <QuartzCore/QuartzCore.h>
@interface Cxnavigationcontroller ()
{
Nsmutablearray *_images; // Image Array
UIView *_bgview; // Background Map
UIView *_blankmask; // Masks
Uiimageview *_imageview; // Image
cgpoint _startpoint; // start point of contact
}
@end
@implementation Cxnavigationcontroller
-(void) viewdidload{
[Superviewdidload];
_images = [nsmutablearrayarray];
if (! iOS7) {
uipangesturerecognizer *pan = [[uipangesturerecognizeralloc] initwithtarge T:selfAction:@selector(panmove:)];
[self. ViewAddgesturerecognizer:p an];
}
}
-(void) Panmove: ( Uipangesturerecognizer *) pan{
if (self.) viewcontrollers. Count <= 1) {
return;
}
cgrect Selff = self. View. frame;
cgpoint location = [Pan locationinview:Key_window];
if (pan. State == Uigesturerecognizerstatebegan) { // start dragging
_startpoint = location;
_imageview. Image = [_imageslastobject];
[key_windowinsertsubview:_bgviewbelowsubview:Self c13>. Tabbarcontroller . View ];
_imageview. Transform = Cgaffinetransformmakescale(kdefaultscale, kdefaultscale);
}Elseif(pan. State == Uigesturerecognizerstatechanged) { // drag in
cgfloat Marginx = location. x - _startpoint. x;
Marginx = marginx > kscreenw ? kscreenw : Marginx;
Marginx = Marginx < 0 ? 0 : Marginx;
Selff. Origin. x = Marginx;
Self. View. frame = Selff;
cgfloat scale = Kdefaultscale + marginx * 1.0 / 6400;
Scale = Marginx = = kscreenw ? 0.5 : scale;
Scale = Marginx = = 0 ? 0 : scale;
_imageview. Transform = Cgaffinetransformmakescale(scale, scale);
cgfloat alpha = Kdefaultalapa -(1 - kdefaultalapa) * Marginx * 1.0 / kscreenw;
Alpha = Marginx = = kscreenw ? Kdefaultalapa : Alpha;
Alpha = Marginx = = 0 ? 0 : Alpha;
_blankmask. Alpha = Alpha;
}Elseif(pan. State == uigesturerecognizerstateended) { // End
cgfloat Marginx = location. x - _startpoint. x;
if (Marginx > ) {
Marginx = marginx > kscreenw ? kscreenw : Marginx;
cgfloat dur = kanimateduration -Marginx * 1.0 / ;
[UIViewanimatewithduration:d ur animations: ^{
cgrect Selff = self. View. frame;
Selff. Origin. x = Key_window. bounds. size. width;
Self. View. frame = Selff;
_blankmask. Alpha = 0;
_imageview. Transform = Cgaffinetransformmakescale(1, 1);
} Completion: ^ (BOOL finished) {
[_images removelastobject];
[_bgview removefromsuperview];
cgrect rect = self. View. frame;
Rect.Origin. x = 0;
Self. View. frame = rect;
[Superpopviewcontrolleranimated:NO];
}];
}Else{
cgfloat Marginx = location. x - _startpoint. x;
Marginx = marginx > ? : Marginx;
Marginx = Marginx < 0 ? 0 : Marginx;
cgfloat dur = Marginx * 1.0 / ;
[UIViewanimatewithduration:0.1 + dur animations: ^ {
cgrect Selff = self. View. frame;
Selff. Origin. x = 0;
Self. View. frame = Selff;
}];
}
}
}
-(void) Pushviewcontroller: (uiviewcontroller *) Viewcontroller animated: (BOOL) animated{
if (self. Viewcontrollers. Count > 0 ) {
if (! iOS7) {
[ self createbg];
}
}
[Super pushviewcontroller: Viewcontroller animated: animated];
}
#pragma mark Create a background
-(void) createbg{
[_imagesaddobject: [self currentscreenimage]];
if (! _bgview) {
_bgview = [[UIView alloc] initwithframe:key_window. Bounds];
_bgview. BackgroundColor = [uicolorblackcolor];
_imageview = [[uiimageview alloc] initwithframe:key_window. Bounds];
_imageview. BackgroundColor = [uicolorclearcolor];
[_bgviewaddsubview:_imageview];
_blankmask = [[UIView alloc] initwithframe:key_window. Bounds];
_blankmask. BackgroundColor = [uicolorblackcolor];
_blankmask. Alpha = Kdefaultalapa;
[_bgviewaddsubview:_blankmask];
}
}
#pragma mark Gets the current screen
-(UIImage *) currentscreenimage{
uigraphicsbeginimagecontextwithoptions(key_window. bounds . size , Self . View . Opaque , 0.0 );
if (self. Topviewcontroller. Tabbarcontroller) {
[self. Topviewcontroller. Tabbarcontroller. View. Layerrenderincontext:uigraphicsgetcurrentcontext()];
}Else{
[self. View . layerrenderincontext:uigraphicsgetcurrentcontext()];
}
UIImage * img = uigraphicsgetimagefromcurrentimagecontext();
uigraphicsendimagecontext();
return img;
}