Implementation of the slide-slip bar effect
Effect
Source
The Sideviewcontroller in Https://github.com/YouXianMing/iOS-Project-Examples
////VIEWCONTROLLER.M//Sideviewcontroller////Created by youxianming on 16/6/6.//copyright©2016 year youxianming. All rights reserved.//#import "ViewController.h"#import "LeftViewController.h"#import "MainViewController.h"#import "uiview+setrect.h"@interfaceViewcontroller () {cgfloat _screenwidth;} @property (nonatomic, strong) Uipangesturerecognizer*pangesture; @property (nonatomic) cgpoint panbeginpoint; @property (nonatomic, Strong) LEFTVIEWC Ontroller*Leftviewcontroller, @property (nonatomic, strong) UIView*Leftview, @property (nonatomic, strong) Mainviewcontroller*Mainviewcontroller, @property (nonatomic, strong) UIView*MainView;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //Init some value._screenwidth =Width; //Add Backgroundview.Uiimageview *backgroundview =[[Uiimageview alloc] initWithFrame:self.view.bounds]; Backgroundview.image= [UIImage imagenamed:@" Back"]; [Self.view Addsubview:backgroundview]; //LeftviewcontrollerSelf.leftviewcontroller =[[Leftviewcontroller alloc] init]; Self.leftview=Self.leftViewController.view; [Self.view AddSubview:self.leftView]; //MainviewcontrollerSelf.mainviewcontroller =[[Mainviewcontroller alloc] init]; Self.mainview=Self.mainViewController.view; [Self.view AddSubview:self.mainView]; //Pan gesture.Self.pangesture =[[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (pangestureevent:)]; [Self.mainview addGestureRecognizer:self.panGesture];}- (void) Pangestureevent: (Uipangesturerecognizer *) gesture {Cgpoint translation=[gesture TranslationInView:gesture.view]; Cgpoint Velocity=[gesture VelocityInView:gesture.view]; CGFloat Gap= _screenwidth/3. f *2; CGFloat sensitiveposition= _screenwidth/2. F; if(Velocity.x <0&& _mainview.x <=0) { //filter off to the left to slide the head of the situation_mainview.x =0. F; } Else { if(Gesture.state = =Uigesturerecognizerstatebegan) { //Start_panbeginpoint =translation; if(_mainview.x >=sensitiveposition) {_panbeginpoint.x-=Gap; } } Else if(Gesture.state = =uigesturerecognizerstatechanged) { //Value Change_mainview.x = translation.x-_panbeginpoint.x; if(_mainview.x <=0) { //filter off to the left to slide the head of the situation_mainview.x =0. F; } } Else if(Gesture.state = =uigesturerecognizerstateended) { //End[UIView animatewithduration:0.20fanimations:^{_mainview.x>= sensitiveposition? (_mainview.x = Gap): (_mainview.x =0); }]; } }}@end
Details
Implementation of the slide-slip bar effect