当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS实现侧拉栏抽屉效果

iOS实现侧拉栏抽屉效果

2019年07月24日  | 移动技术网移动技术  | 我要评论

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

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


抽屉效果所需第三方类库

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


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

appdelegate.h文件代码:

 <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抽屉效果有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网