我想在ios应用程序中创建一个菜单。当我单击导航控制器中的按钮时,菜单应该出现,当我再次点击它时,它应该关闭。
答案 0 :(得分:1)
下载库并找到REMenu类。在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**
替换以下代码
//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;
答案 1 :(得分:0)
你可以创建一个表或自定义视图,我也面临同样的问题,我通过表视图
来做到这一点初始化菜单项:
menuItem = [[NSArray alloc] initWithObjects:@“Item1”,@“Item2”,@“Item3”,nil];
按钮点击:
- (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;
}