从导航栏下拉菜单

Pull down menu from Navigation bar

有谁知道将可伸缩菜单附加到导航栏底部的好的解决方案吗?

我找到了这个:https://github.com/mentionapp/mntpulltoreact,但是这个有下拉整个视图的行为,不放手,然后用手指拖动选择一个想要的项目。

Zappos 应用程序是我正在寻找的完美示例。有谁知道他们本可以使用什么或现有的解决方案?我搜索了 cocoacontrols 并没有找到太多。

做这样的事情对你有用吗?那么当然您可以将您需要的任何菜单按钮添加到菜单视图中。

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];

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

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