欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS实现侧拉栏抽屉效果

程序员文章站 2023-08-12 15:52:40
本文实例介绍了ios实现侧拉栏抽屉效果的相关代码,分享给大家供大家参考,具体内容如下 需要导入第三方的类库如下: 抽屉效果所需第三方类库下载 效果:既可以两侧...

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

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

iOS实现侧拉栏抽屉效果

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

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

iOS实现侧拉栏抽屉效果

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