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: