iOS 純代碼寫個(gè)側(cè)滑欄功能
代碼原理就是使用UIView并對(duì)其移動(dòng)來(lái)完成,一個(gè)twoView作為側(cè)滑欄,一個(gè)oneView作為主界面,需要彈出側(cè)滑欄時(shí)對(duì)twoView向右移動(dòng)200,當(dāng)隱藏側(cè)滑欄時(shí),向左移動(dòng)200就行了,twoVIew初始的x地址為-200。
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> @property (strong, nonatomic) NSArray *list; @end
//
// ViewController.m
// First
//
// Created by shanreal-iOS on 17/10/16.
// Copyright © 2017年 shanreal.LongZhenHao. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)UIView* oneView;
@property(nonatomic,strong)UIView* twoView;
@property(nonatomic,assign)Boolean isShow;
@property(nonatomic,strong)UIButton* btn_back;
@property(nonatomic,strong)UIButton* btn_show;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initLeftMenu];
}
-(void)initLeftMenu{
//self.view.backgroundColor = [UIColor whiteColor];
_isShow = NO;
_oneView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width+200, self.view.frame.size.height)];
_oneView.backgroundColor = [UIColor whiteColor];
_twoView=[[UIView alloc]initWithFrame:CGRectMake(-200, 0, 200, self.view.frame.size.height)];
_twoView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:_oneView];
[self.view addSubview:_twoView];
_oneView.userInteractionEnabled=YES;
UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backClick)];
[_oneView addGestureRecognizer:tapGesture1];
_btn_show = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-75, self.view.frame.size.height/2-15, 150, 30)];
_btn_show.backgroundColor = [UIColor whiteColor];
[_btn_show setTitle:@"彈出側(cè)滑欄" forState:UIControlStateNormal];
[_btn_show setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_btn_show addTarget:self action:@selector(oneClick) forControlEvents:UIControlEventTouchUpInside];
[self.oneView addSubview:_btn_show];
_btn_back = [[UIButton alloc]initWithFrame:CGRectMake(20, 100, 150, 30)];
_btn_back.backgroundColor = [UIColor whiteColor];
[_btn_back setTitle:@"返回" forState:UIControlStateNormal];
[_btn_back setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_btn_back addTarget:self action:@selector(twoClick) forControlEvents:UIControlEventTouchUpInside];
[self.twoView addSubview:_btn_back];
}
-(void)oneClick{
[UIView animateWithDuration:0.7 animations:^{
//[_oneView setTransform:CGAffineTransformMakeTranslation(200, 0)];
[_twoView setTransform:CGAffineTransformMakeTranslation(200, 0)];
}];
_isShow = YES;
}
-(void)twoClick{
[UIView animateWithDuration:0.7 animations:^{
//[_oneView setTransform:CGAffineTransformMakeTranslation(-200, 0)];
[_twoView setTransform:CGAffineTransformMakeTranslation(-200, 0)];
}];
_isShow = NO;
}
-(void)backClick{
if(_isShow == YES)
[self performSelector:@selector(twoClick)];
}
@end
以上這篇iOS 純代碼寫個(gè)側(cè)滑欄功能就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
iOS中的AutoLayout使用實(shí)踐總結(jié)
在對(duì)界面進(jìn)行布局的時(shí)候,我們經(jīng)常使用AutoLayout對(duì)界面進(jìn)行布局適配。下面這篇文章主要給大家介紹了iOS中AutoLayout使用實(shí)踐的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-12-12
iOS中searchBar(搜索框)光標(biāo)初始位置后移
這篇文章主要介紹了iOS中searchBar(搜索框)光標(biāo)初始位置后移的關(guān)鍵代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08
iOS10適配之權(quán)限Crash問(wèn)題的完美解決方案
這篇文章主要為大家詳細(xì)介紹了iOS10適配之權(quán)限Crash問(wèn)題的完美解決方案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
IOS用AFN發(fā)送字符串形式的Json數(shù)據(jù)給服務(wù)器實(shí)例
本篇文章主要介紹了IOS用AFN發(fā)送字符串形式的Json數(shù)據(jù)給服務(wù)器實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-04-04
iphone的safari瀏覽器中實(shí)現(xiàn)全屏瀏覽的方法
這篇文章主要介紹了iphone的safari瀏覽器中實(shí)現(xiàn)全屏瀏覽的方法,同時(shí)介紹了Add to Home Screen功能的實(shí)現(xiàn)方法,需要的朋友可以參考下2014-06-06
IOS AFNetworking的Post失敗及requestSerializer的正確使用
這篇文章主要介紹了IOS AFNetworking的Post失敗及requestSerializer的正確使用的相關(guān)資料,需要的朋友可以參考下2017-05-05

