iOS dev-ios Customize anywhere right slide pop view Controller

Source: Internet
Author: User

iOS custom anywhere right slide Pop view Controller IOS7.0 After the system provides a native from the left edge of the slide pop out of the stack, you can also customize the left edge pop out of the stack, will be introduced in the next article, this article introduces the method of adding gestures to achieve the iOS current screen anywhere (non-specified left edge) Right slide pop view controller out of the stack. The code is as follows:

lxxpopviewcontroller.m//  any point right slide pop////  Created by Lotheve on 15/6/12.//  Copyright (c) 2015 Lotheve. All Rights reserved.//

#import "LXXPopViewController.h" #define Keywindow[uiapplication Sharedapplication].keywindow @interface Lxxpopviewcontroller () @property (Nonatomic,strong) Nsmutablearray *snapshotarray; @property (nonatomic, Strong) UIView *backview; @property (nonatomic, strong) Uiimageview *imageview; @property (nonatomic, Strong) Uipangesturerecognizer *pan; @property (nonatomic, assign) Cgpoint startPoint; @property (nonatomic, assign) Cgpoint EndPoint, @end @implementation Lxxpopviewcontroller-(Instancetype) Initwithnibname: (NSString *) Nibnameornil Bundle: ( NSBundle *) nibbundleornil{    if (self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]) {        //Data initialization        _snapshotarray = [Nsmutablearray array];    }    return self;}

-(void) viewdidload {    [super viewdidload];     Add pop gesture    _pan = [[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector (panaction:)];    ???: What's the use of/** this sentence is: Do not accept other touch events **/    [Self.view Addgesturerecognizer:_pan] before the gesture has failed. <span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " > </span>

-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated{    // Screenshot and Save Uigraphicsbeginimagecontextwithoptions (Cgsizemake (Self.view.frame.size.width, Self.view.frame.size.height) , NO, 1);    [Self.view drawviewhierarchyinrect:cgrectmake (0, 0, self.view.frame.size.width, self.view.frame.size.height) Afterscreenupdates:no];    UIImage *snapshot = Uigraphicsgetimagefromcurrentimagecontext ();    Uigraphicsendimagecontext ();    [_snapshotarray Addobject:snapshot];    [Super Pushviewcontroller:viewcontroller animated:animated];}

-(uiviewcontroller*) popviewcontrolleranimated: (BOOL) animated{    [_snapshotarray removelastobject];    return [Super popviewcontrolleranimated:animated];}

#pragma mark-privatemethods-(void) Panaction: (Uipangesturerecognizer *) pangesturerecognizer{if (    Self.viewControllers.count = = 1) {return;        } if (pangesturerecognizer.state = = Uigesturerecognizerstatebegan) {NSLog (@ "Start sliding");        Self.startpoint = [Pangesturerecognizer Locationinview:keywindow];            if (!_backview) {_backview = [[UIView alloc]initwithframe:[uiscreen mainscreen].bounds];        _backview.backgroundcolor = [Uicolor blackcolor];            } if (!_imageview) {_imageview = [[Uiimageview alloc]initwithframe:[uiscreen mainscreen].bounds];            _imageview.backgroundcolor = [Uicolor Clearcolor];        _imageview.image = [_snapshotarray lastobject];        } [_backview Addsubview:_imageview];           [Self.view.superview Insertsubview:_backview BelowSubview:self.view];        }else if (pangesturerecognizer.state = = uigesturerecognizerstateended) {NSLog (@ "End swipe"); Self.endpoint = [PangeSturerecognizer Locationinview:keywindow];    [Self judgewhethertopop];        }else{cgpoint currentpoint =[pangesturerecognizer Locationinview:keywindow];        CGFloat MoveX = currentpoint.x-self.startpoint.x;    [Self Moveviewmaskwithx:movex]; }}

Mobile View-(void) Moveviewmaskwithx: (cgfloat) movex{if (MoveX >= 0 && moveX <= [UIScreen MAINSCREEN].BOUNDS.S        Ize.width) {CGRect frame = self.view.frame;        frame.origin.x = MoveX;        Self.view.frame = frame;        Transparency Gradient Float alpha = (Movex/[uiscreen mainscreen].bounds.size.width) *2.0/3+1.0/3;        _imageview.alpha = Alpha;        Scales float scale = (movex/3200) +0.9;    _imageview.transform = Cgaffinetransformmakescale (scale, scale); }}//determines and executes whether pop-(void) judgewhethertopop{if (Self.endpoint.x-self.startpoint.x >) {[UIView ANIMATEWITHD        uration:0.3 animations:^{[self moveviewmaskwithx:[uiscreen mainscreen].bounds.size.width];            } completion:^ (BOOL finished) {[Self popviewcontrolleranimated:no];            [_backview Removefromsuperview];            _backview = nil;            _imageview = nil;            CGRect frame = self.view.frame;            frame.origin.x = 0; Self.view. frame = frame;    }];        }else{[UIView animatewithduration:0.3 animations:^{[self moveviewmaskwithx:0];            } completion:^ (BOOL finished) {[_backview Removefromsuperview];            _backview = nil;        _imageview = nil;    }]; }} @end

iOS dev-ios Customize anywhere right slide pop view Controller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.