简体   繁体   中英

how to create menu in iOS NavigationController like android?

i want to create a menu in my ios application. 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. In REMenu find the method and replace the code.

- (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

For Initialising Menu Item :

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;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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