Ios 滑动抽屉在对象c的左右两侧打开和关闭

Ios 滑动抽屉在对象c的左右两侧打开和关闭,ios,objective-c,iphone,slide,Ios,Objective C,Iphone,Slide,我一直在尝试开发一款iOS应用程序,它有一个滑动抽屉,类似于Android中的导航抽屉。。。一切正常,除了滑动抽屉可以使用左右滑动手势打开和关闭。。。 我需要它只关闭在左扫手势和打开使用右扫手势 正在添加下面的代码。。。请考虑在iOS开发中很新… #import "mainViewController.h" @interface mainViewController () @end @implementation mainViewController @synthesize m

我一直在尝试开发一款iOS应用程序,它有一个滑动抽屉,类似于Android中的导航抽屉。。。一切正常,除了滑动抽屉可以使用左右滑动手势打开和关闭。。。 我需要它只关闭在左扫手势和打开使用右扫手势

正在添加下面的代码。。。请考虑在iOS开发中很新…

 #import "mainViewController.h"

 @interface mainViewController ()

 @end

 @implementation mainViewController

 @synthesize menuDrawerWidth, menuDrawerX,recognizer_open, recognizer_close;

- (void)viewDidLoad {
[super viewDidLoad];
menuDrawer = [[[NSBundle mainBundle] loadNibNamed:@"SlideDrawer" owner:self options:nil]objectAtIndex:0];
menuDrawerWidth= 250 ;
int statusbarHeight= [UIApplication sharedApplication].statusBarFrame.size.height;
menuDrawerX= self.view.frame.origin.x- menuDrawerWidth;
menuDrawer.frame= CGRectMake(menuDrawerX, menuDrawer.frame.origin.y+statusbarHeight, menuDrawer.frame.size.width, menuDrawer.frame.size.height-statusbarHeight);
// menuDrawer.backgroundColor=[UIColor colorWithRed:0.18 green:0.09 blue:0.29 alpha:1.0];
recognizer_close= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
recognizer_open= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
recognizer_close.direction= UISwipeGestureRecognizerDirectionLeft;
recognizer_open.direction= UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:recognizer_close];
[self.view addGestureRecognizer:recognizer_open];
[self.view addSubview:menuDrawer];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }



   // In a storyboard-based application, you will often want to do a little   preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
  }


 -(void) handleSwipes:(UIGestureRecognizer *) sender{
[self drawerAnimation];

 }
 -(void) drawerAnimation{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:-10];
CGFloat new_x = 0;
if(menuDrawer.frame.origin.x<self.view.frame.origin.x)
{
    new_x= menuDrawer.frame.origin.x+menuDrawerWidth;
    UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:menuDrawer.bounds];
    menuDrawer.layer.masksToBounds = NO;
    menuDrawer.layer.shadowColor = [UIColor blackColor].CGColor;
    menuDrawer.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
    menuDrawer.layer.shadowOpacity = 0.5f;
    menuDrawer.layer.shadowPath = shadowPath.CGPath;
}
else{
    new_x= menuDrawer.frame.origin.x-menuDrawerWidth;
    UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:menuDrawer.bounds];
    menuDrawer.layer.masksToBounds = NO;
    menuDrawer.layer.shadowColor = [UIColor blackColor].CGColor;
    menuDrawer.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
    menuDrawer.layer.shadowOpacity = 0.0f;
    menuDrawer.layer.shadowPath = shadowPath.CGPath;
}
menuDrawer.frame= CGRectMake(new_x, menuDrawer.frame.origin.y, menuDrawer.frame.size.width, menuDrawer.frame.size.height);
[UIView commitAnimations];
 }


 @end
#导入“mainViewController.h”
@接口mainViewController()
@结束
@实现主视图控制器
@合成菜单宽度、菜单宽度、识别器打开、识别器关闭;
-(无效)viewDidLoad{
[超级视图下载];
menuDrawer=[[NSBundle mainBundle]loadNibNamed:@“SlideDrawer”所有者:自选项:nil]对象索引:0];
menuDrawerWidth=250;
int statusbarHeight=[UIApplication sharedApplication].statusBarFrame.size.height;
menuDrawerX=self.view.frame.origin.x-menuDrawerWidth;
menuDrawer.frame=CGRectMake(menuDrawerX,menuDrawer.frame.origin.y+statusbarHeight,menuDrawer.frame.size.width,menuDrawer.frame.size.height statusbarHeight);
//menuDrawer.backgroundColor=[UIColor COLOR WITHRED:0.18绿色:0.09蓝色:0.29阿尔法:1.0];
识别器_close=[[UISweepGestureRecognitizer alloc]initWithTarget:self action:@selector(HandleSweeps:)];
识别器_open=[[UISweepGestureRecognitizer alloc]initWithTarget:self action:@selector(HandleSweeps:)];
识别器_close.direction=UISweepGestureRecognizerDirectionLeft;
识别器_open.direction=UISweepGestureRecognitizerDirectionRight;
[self.view addgesturecognizer:recognizer_close];
[self.view addgesturecognizer:recognizer_open];
[self.view addSubview:menuDrawer];
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
//在基于故事板的应用程序中,您通常需要在导航之前做一些准备
-(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方{
//使用[segue destinationViewController]获取新的视图控制器。
//将选定对象传递给新的视图控制器。
}
-(无效)免提湿巾:(UIgestureRecognitor*)发送器{
[自我介绍];
}
-(无效)付款人通知{
[UIView beginAnimations:nil上下文:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:-10];
CGFloat new_x=0;

if(menuDrawer.frame.origin.x)你应该看看Mutual Mobile的。它是一个具有许多功能的惊人抽屉库。
如果您的应用程序中只需要一个抽屉,我建议您使用它。

如果你想自己学习怎么做,为什么不看看他们的代码?

我已经检查过了…但这与我需要做的略有不同…当滑动抽屉时,将整个布局向右滑动…我需要抽屉应该位于主视图控制器上方,类似于android中的抽屉。。。