国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS 純代碼寫個側滑欄功能

2019-10-21 18:42:12
字體:
來源:轉載
供稿:網友

代碼原理就是使用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 純代碼寫個側滑欄功能就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 威远县| 福贡县| 玛沁县| 南召县| 石首市| 盐山县| 稻城县| 抚顺县| 文昌市| 那曲县| 九寨沟县| 吕梁市| 陈巴尔虎旗| 定兴县| 井陉县| 英吉沙县| 阿合奇县| 西林县| 太原市| 红安县| 凤山市| 金门县| 新巴尔虎右旗| 阳原县| 吴忠市| 宁安市| 龙山县| 沂南县| 个旧市| 离岛区| 江达县| 镇原县| 成武县| 安徽省| 张家口市| 辰溪县| 宣恩县| 竹溪县| 沁阳市| 云霄县| 瑞昌市|