Effect
Source: Https://github.com/YouXianMing/iOS-Project-Examples in the Sideviewcontroller
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"
@interface Viewcontroller () {cgfloat _screenwidth;}
@property (nonatomic, strong) Uipangesturerecognizer *pangesture;
@property (nonatomic) Cgpoint panbeginpoint;
@property (nonatomic, strong) Leftviewcontroller *leftviewcontroller;
@property (nonatomic, strong) UIView *leftview;
@property (nonatomic, strong) Mainviewcontroller *mainviewcontroller;
@property (nonatomic, strong) UIView *mainview;
@end @implementation Viewcontroller-(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];
Leftviewcontroller Self.leftviewcontroller = [[Leftviewcontroller alloc] init];
Self.leftview = Self.leftViewController.view;
[Self.view AddSubview:self.leftView];
Mainviewcontroller Self.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 left side of the case _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 changes _mainview.x = translation.x-_pan
Beginpoint.x;
if (_mainview.x <= 0) {//filter off to the left side of the case _mainview.x = 0.F; } else if (gesture.state = uigesturerecognizerstateended) {//end [UIView animatewithduration:0.20f ANI mations:^{_mainview.x >= sensitiveposition?
(_mainview.x = Gap): (_mainview.x = 0);
}];
}}} @end
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.