简体   繁体   English

如何在iOS NavigationController中创建菜单(如android)?

[英]how to create menu in iOS NavigationController like android?

i want to create a menu in my ios application. 我想在我的ios应用程序中创建一个菜单。 When i click the button in navigation controller the menu should appear and when i click again it should close. 当我单击导航控制器中的按钮时,菜单应该出现,当我再次单击时,它应该关闭。 我想要像这张图片一样

Download library and find the REMenu class. 下载库并找到REMenu类。 In REMenu find the method and replace the code. 在REMenu中找到方法并替换代码。

- (void)showFromRect:(CGRect)rect inView:(UIView *)view
{
......
// In this method find the below code
// Set up frames
//
self.menuWrapperView.frame = CGRectMake(0, -self.combinedHeight - navigationBarOffset, rect.size.width, self.combinedHeight + navigationBarOffset);
self.menuView.frame = self.menuWrapperView.bounds;
if (REUIKitIsFlatMode() && self.liveBlur) {
    self.toolbar.frame = self.menuWrapperView.bounds;
}
self.containerView.frame = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
self.backgroundButton.frame = self.containerView.bounds;

// Add subviews**

Replace the below code 替换下面的代码

//self.menuWrapperView.frame = CGRectMake(0, -self.combinedHeight - navigationBarOffset, rect.size.width, self.combinedHeight + navigationBarOffset);
self.menuWrapperView.frame = CGRectMake(0, 0, rect.size.width/2, self.combinedHeight + navigationBarOffset);
self.menuView.frame = self.menuWrapperView.bounds;
if (REUIKitIsFlatMode() && self.liveBlur) {
    self.toolbar.frame = self.menuWrapperView.bounds;
}
//self.containerView.frame = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
self.containerView.frame = CGRectMake(rect.size.width/2, rect.origin.y, rect.size.width/2, rect.size.height);
self.backgroundButton.frame = self.containerView.bounds;

U can create a table or custom view, I also faced same issue , I do this by table view U可以创建表或自定义视图,我也遇到同样的问题,我可以通过表视图执行此操作

For Initialising Menu Item : 对于初始化菜单项:

menuItem=[[NSArray alloc]initWithObjects:@"Item1",@"Item2",@"Item3", nil]; menuItem = [[NSArray alloc] initWithObjects:@“ Item1”,@“ Item2”,@“ Item3”,nil];

For Button Click : 对于按钮单击:

- (IBAction)showMenuItme:(id)sender {
    self.btnMenu.selected=!self.btnMenu.selected;
    if (self.btnMenu.selected) {
        [self.tblMenu setHidden:NO];
    }
    else
    {
        [self.tblMenu setHidden:YES];
    }

}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.tblMenu setHidden:YES];
    self.btnMenu.selected=NO;
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [menuItem count];

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier=@"Cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.textLabel.text=[menuItem objectAtIndex:indexPath.row];
    return cell;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM