iOS实现侧拉栏抽屉效果

时间:2022-08-24 12:43:14

本文实例介绍了ios实现侧拉栏抽屉效果的相关代码,分享给大家供大家参考,具体内容如下

需要导入第三方的类库如下:

iOS实现侧拉栏抽屉效果

抽屉效果所需第三方类库下载

效果:既可以两侧都实现抽屉效果也可只实现左侧栏或者右侧栏的抽屉效果

iOS实现侧拉栏抽屉效果

iOS实现侧拉栏抽屉效果

关于抽屉效果主要是appdelegate的代码

appdelegate.h文件代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<span style="font-size:18px;"><span style="font-size:18px;">#import <uikit/uikit.h>
 
@interface yjfappdelegate : uiresponder <uiapplicationdelegate>
 
@property (strong, nonatomic) uiwindow *window;
 
@end</span></span>
appdelegate.m文件代码
 
<span style="font-size:18px;"><span style="font-size:24px;"><span style="font-size:18px;">#import "yjfappdelegate.h"
#import "customizednavigationcontroller.h"
#import "firstviewcontroller.h"
#import "secondviewcontroller.h"
#import "thirdviewcontroller.h"
@implementation yjfappdelegate
 
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions
{
 self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];
 //主视图
 firstviewcontroller *firstvc = [[firstviewcontroller alloc] init];
 //左边视图
 secondviewcontroller *secondvc = [[secondviewcontroller alloc] init];
 //右边视图
 thirdviewcontroller *thirdvc = [[thirdviewcontroller alloc] init];
 
 customizednavigationcontroller *navigationvc = [[customizednavigationcontroller alloc] initwithrootviewcontroller:firstvc];
 
 
 customizednavigationcontroller *leftnavigationvc = [[customizednavigationcontroller alloc] initwithrootviewcontroller:secondvc];
 
 customizednavigationcontroller *rightnavigationvc = [[customizednavigationcontroller alloc] initwithrootviewcontroller:thirdvc];
 
 //抽屉管理 第三方
 //该第三方既可以只实现打开左侧栏也可以实现打开右侧栏,还可以同时都实现
 mmdrawercontroller *roovc = [[mmdrawercontroller alloc] initwithcenterviewcontroller:navigationvc leftdrawerviewcontroller:leftnavigationvc rightdrawerviewcontroller:rightnavigationvc];
 
 //只实现打开左侧栏
 //mmdrawercontroller *roovcleft = [[mmdrawercontroller alloc] initwithcenterviewcontroller:navigationvc leftdrawerviewcontroller:firstvc];
 //只实现打开右侧栏
 //mmdrawercontroller *roovcright = [[mmdrawercontroller alloc] initwithcenterviewcontroller:navigationvc rightdrawerviewcontroller:thirdvc];
 
 //指定window的根视图
 self.window.rootviewcontroller = roovc;
 //测了门的宽度
 [roovc setmaximumleftdrawerwidth:270];
 //设置侧拉门开与关的动画
 [roovc setopendrawergesturemodemask:mmopendrawergesturemodeall];
 [roovc setclosedrawergesturemodemask:mmclosedrawergesturemodeall];
 //侧开内容展示效果
 //设置向左滑动打开右侧栏
 [[mmexampledrawervisualstatemanager sharedmanager] setrightdraweranimationtype:mmdraweranimationtypenone];
 //设置向右滑动打开左侧栏
 [[mmexampledrawervisualstatemanager sharedmanager] setleftdraweranimationtype:mmdraweranimationtypenone];
 
 //
 [roovc setdrawervisualstateblock:^(mmdrawercontroller *drawercontroller, mmdrawerside drawerside, cgfloat percentvisible) {
  mmdrawercontrollerdrawervisualstateblock block;
  block = [[mmexampledrawervisualstatemanager sharedmanager]
     drawervisualstateblockfordrawerside:drawerside];
  if(block){
   block(drawercontroller, drawerside, percentvisible);
  }
 
 }];
 
 
 
 
 
 self.window.backgroundcolor = [uicolor whitecolor];
 [self.window makekeyandvisible];
 return yes;
}</span>
</span>
</span>

以上就是本文的全部内容,希望对大家学习ios抽屉效果有所帮助。