时间:2021-05-20
代码原理就是使用UIView并对其移动来完成,一个twoView作为侧滑栏,一个oneView作为主界面,需要弹出侧滑栏时对twoView向右移动200,当隐藏侧滑栏时,向左移动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:@"弹出侧滑栏" 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 纯代码写个侧滑栏功能就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例为大家分享了iOSpush侧滑返回功能的具体代码,供大家参考,具体内容如下开启iOS自带的push的侧滑返回功能(只有左侧边缘地带响应侧滑返回,并不是全
最近项目中用到下拉刷新与侧滑删除需要同时实现的情形,所以对LRecyclerView进行了一些了解,在测试侧滑功能时,发现iOS阻塞效果不完整,即当条目处于侧滑
先解释一下这个标题,说的是实现App侧滑返回功能只需要一行代码就能搞定,怎么做到的我待会会说。侧滑所指的就是侧滑返回,后面的介绍过程我将用侧滑表面其意。请看侧滑
需求我们在开发中经常遇见这样的需求,就是A视图没有导航,pushB视图后导航栏。然后要求可以使用iOS的系统侧滑返回功能。类似如下的功能:问题在处理这个需求的时
闲来无事,写个玩安卓的首页,实现多布局、banner的效果。其中涉及知识点侧滑,pageview切换页面,页面跳转传值及回调数据(在侧滑里)。这些都是基于自己学