Write iOS7 sidebar using Uiscreenedgepangesturerecognizer

Source: Internet
Author: User

Write iOS7 sidebar using Uiscreenedgepangesturerecognizer

A Uiscreenedgepangesturerecognizer looks for panning (dragging) gestures this start near an edge of the. The system uses screen edge gestures in some cases to initiate view controller transitions. You can use this class to replicate the same gesture behavior for your own actions.

Uiscreenedgepangesturerecognizer looks like a pan gesture, which is a pan gesture that detects the edges of the screen. The system uses this gesture when certain controller transitions are in use. You can also use this gesture to do other things.

Source:

#import "RootViewController.h"@interfaceRootviewcontroller () <UIGestureRecognizerDelegate>{cgfloat _centerx;    CGFloat _centery; UIView*_backgroundview;}@end@implementationRootviewcontroller- (void) viewdidload{[Super Viewdidload]; //Storage coordinates_centerx = self.view.bounds.size.width/2; _centery= Self.view.bounds.size.height/2; Self.view.backgroundColor=[Uicolor Blackcolor]; //pan gestures at the edge of the screen (higher priority than other gestures)Uiscreenedgepangesturerecognizer *leftedgegesture =[[Uiscreenedgepangesturerecognizer alloc] Initwithtarget:self    Action: @selector (handleleftedgegesture:)]; Leftedgegesture.edges= Uirectedgeleft;//The left edge of the screen responds[Self.view Addgesturerecognizer:leftedgegesture];//Add a self.view to the//set a uiview to replace Self.view,self.view to use as a background_backgroundview =[[UIView alloc] initWithFrame:self.view.bounds]; _backgroundview.backgroundcolor=[Uicolor Yellowcolor];        [Self.view Addsubview:_backgroundview]; //the view displayedUIView *showview_01 = [[UIView alloc] Initwithframe:cgrectmake (0,0, the, $)]; Showview_01.tag=0x1; Showview_01.backgroundcolor=[Uicolor Redcolor]; [_backgroundview addsubview:showview_01];}- (void) Handleleftedgegesture: (Uiscreenedgepangesturerecognizer *) gesture{//Gets the view that is currently being touchedUIView *view =[Self.view hittest:[gesture LocationInView:gesture.view] withevent:nil]; NSLog (@"tag =%ld", (Long) View.tag); if(Uigesturerecognizerstatebegan = = Gesture.state | |uigesturerecognizerstatechanged==gesture.state) {//calculates the coordinate value based on the view of the touch gestureCgpoint translation =[gesture TranslationInView:gesture.view]; NSLog (@"%@", Nsstringfromcgpoint (translation)); NSLog (@"in Progress"); //to set_backgroundview.center = Cgpointmake (_centerx +translation.x, _centery); }    Else    {        //Restore Settings[UIView animatewithduration:.3animations:^{_backgroundview.center=Cgpointmake (_centerx, _centery);    }]; }}@end
ROOTVIEWCONTROLLER.M

Effects such as:

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.