Ios 导航栏中的下拉菜单

Ios 导航栏中的下拉菜单,ios,objective-c,menu,uinavigationbar,custom-controls,Ios,Objective C,Menu,Uinavigationbar,Custom Controls,有人知道在导航栏底部附加可伸缩菜单的好方法吗 我发现了:,但它的行为是向下拉动整个视图,不放手,然后通过拖动手指来选择所需的项目 Zappos应用程序是我想要的一个完美的例子。有人知道他们可能在使用什么或现有的解决方案吗?我在椰子树上搜索过,没找到多少。 你愿意做这样的工作吗?当然,您可以将所需的任何菜单按钮添加到菜单视图中 UIView * menu; UIButton * activate; int menuHeight; int buttonHeight; -(void)toggleMe

有人知道在导航栏底部附加可伸缩菜单的好方法吗

我发现了:,但它的行为是向下拉动整个视图,不放手,然后通过拖动手指来选择所需的项目

Zappos应用程序是我想要的一个完美的例子。有人知道他们可能在使用什么或现有的解决方案吗?我在椰子树上搜索过,没找到多少。

你愿意做这样的工作吗?当然,您可以将所需的任何菜单按钮添加到菜单视图中

UIView * menu;
UIButton * activate;
int menuHeight;
int buttonHeight;

-(void)toggleMenu:(UIButton*)sender{

    [sender setUserInteractionEnabled:NO];

    [self.view bringSubviewToFront:menu];

    if (sender.tag == 1000){

        [UIView transitionWithView:menu duration:0.3 options:UIViewAnimationOptionCurveEaseInOut animations:^{

            CGRect frame = CGRectMake(menu.frame.origin.x,menu.frame.origin.y - menu.frame.size.height + buttonHeight ,menu.frame.size.width,menu.frame.size.height);

            menu.frame = frame;

            [sender setUserInteractionEnabled:YES];

        } completion:nil];

        sender.tag = 2000;

    } else {

        [UIView transitionWithView:menu duration:0.3 options:UIViewAnimationOptionCurveEaseInOut animations:^{

            CGRect frame = CGRectMake(menu.frame.origin.x,menu.frame.origin.y + menu.frame.size.height - buttonHeight  ,menu.frame.size.width,menu.frame.size.height);

            menu.frame = frame;

            [sender setUserInteractionEnabled:YES];

        } completion:nil];

        sender.tag = 1000;
    }

}



menuHeight = 100;
buttonHeight = 20;

activate = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[activate addTarget:self action:@selector(toggleMenu:) forControlEvents:UIControlEventTouchUpInside];
[activate setTitle:@"Menu" forState:UIControlStateNormal];
activate.frame = CGRectMake(80.0, menuHeight - buttonHeight, 70.0, buttonHeight);
activate.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;

activate.tag = 2000;

menu = [[UIView alloc] initWithFrame:CGRectMake(0,0 - menuHeight + buttonHeight,self.view.bounds.size.width, menuHeight)];

menu.autoresizingMask =  UIViewAutoresizingFlexibleWidth;

menu.backgroundColor = [UIColor grayColor];

[self.view addSubview:menu];
[menu addSubview:activate];

然后,您可以使用一些约束来向下移动表,或者不向下移动。这是未经测试,但应该让你指向正确的方向

-(void)toggleMenu:(UIButton*)sender{


    UIView * menu;

    [sender setUserInteractionEnabled:NO];

    [self.view bringSubviewToFront:menu];

    id topGuide = self.topLayoutGuide;
    id bottomGuide = self.bottomLayoutGuide;

    NSDictionary * viewsDictionary;

    viewsDictionary = NSDictionaryOfVariableBindings(myTable, topGuide, bottomGuide, menu);

    NSArray * newVertConstraint;


    if (sender.tag == 1000){

        newVertConstraint = [NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"V:|[bottomGuide][menu(==%f)][myTable][bottomGuide]|", 0.0] options:0 metrics: 0 views:viewsDictionary];

        sender.tag = 2000;

    } else {
        newVertConstraint = [NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"V:|[bottomGuide][menu(==%f)][myTable][bottomGuide]|", menu.frame.size.height] options:0 metrics: 0 views:viewsDictionary];        
        sender.tag = 1000;
    }

    [self.view removeConstraints:vertConstraint];

    [self.view addConstraints:newVertConstraint];
    [self.view setNeedsUpdateConstraints];
    [UIView animateWithDuration:1.5 animations:^{
        [self.view layoutIfNeeded];
    }];

    vertConstraint = newVertConstraint;

}




NSArray * vertConstraint;

UITableView * myTable = [[UITableView alloc] init];
[self.view addSubview:myTable];


self.automaticallyAdjustsScrollViewInsets = NO;
[myTable setTranslatesAutoresizingMaskIntoConstraints: NO];
[menu setTranslatesAutoresizingMaskIntoConstraints: NO];

id topGuide = self.topLayoutGuide;
id bottomGuide = self.bottomLayoutGuide;

NSDictionary * viewsDictionary;

viewsDictionary = NSDictionaryOfVariableBindings(myTable, topGuide, bottomGuide, menu);

vertConstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[bottomGuide][menu(==0)][myTable][bottomGuide]|" options:0 metrics: 0 views:viewsDictionary];

[self.view addConstraints:vertConstraint];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[menu]|" options:0 metrics: 0 views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[myTable]|" options:0 metrics: 0 views:viewsDictionary]];

这肯定有用!我必须弄清楚如何使它向下推我的tableView标题,但这不会花费太长时间。您知道如何在向下拉时使此视图粘贴到导航栏的底部吗?而不是整个滚动视图?