Implementation of the slide-slip bar effect

Source: Internet
Author: User

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

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.