【问题标题】:Slide menu with storyboards ios 7带有故事板ios 7的幻灯片菜单
【发布时间】:2016-05-30 16:57:53
【问题描述】:

我需要在我的应用程序上实现一个幻灯片菜单(如 facebook 应用程序上的那个),但我也希望在我的视图上有链接到其他视图的按钮,例如在我的主视图上我有一个按钮单击转到 OptionView,但我也想要一个链接到 OptionView 的幻灯片菜单,我正在使用情节提要和 xcode 5,我想知道是否有人可以帮助我弄清楚如何创建幻灯片菜单

【问题讨论】:

    标签: xcode storyboard slide


    【解决方案1】:

    您可以使用它来产生想法/使用开源: https://github.com/aryaxt/iOS-Slide-Menu

    或者你可以像这样实现它:

    在导航栏中添加UIBarButtonItem:

    UIBarButtonItem *rightRevealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"] style:UIBarButtonItemStyleBordered target: self action:@selector(rightRevealToggle:)];
    self.navigationItem.rightBarButtonItem = rightRevealButtonItem;
    

    实现rightRevealToggle:

     - (void)rightRevealToggle:(id)sender
     {
         float width = self.view.frame.size.width;
         float height = self.view.frame.size.height;
         self.navigationItem.rightBarButtonItem.enabled = FALSE;
    
         CGRect rearViewFrame = _rearViewController.view.frame;
         float deltaToMoveRearView = _rearViewController.datePicker.frame.size.width;//0.25f * width;
         //slide the rear view inside
         if(_rearViewController.view.hidden && ![sender isKindOfClass:[UISwipeGestureRecognizer class]])
         {
             _rearViewController.view.hidden = FALSE;
             [UIView animateWithDuration:0.7f animations:^{
                 _rearViewController.view.frame = CGRectMake(width - deltaToMoveRearView,rearViewFrame.origin.y,rearViewFrame.size.width,rearViewFrame.size.height);
            _contentViewController.view.frame = CGRectMake(-deltaToMoveRearView , 0, width, _contentViewController.view.frame.size.height);
            NSLog(@"3: frame: x:%f y:%f",_contentViewController.view.frame.origin.x,_contentViewController.view.frame.origin.y);
        } completion:^(BOOL finished){
            self.navigationItem.rightBarButtonItem.enabled = TRUE;
        }];
    }
    //slide the rear view outside
    else
    {
        self.rearViewController.view.hidden = FALSE;
        [UIView animateWithDuration:0.7f animations:^{
            _rearViewController.view.frame = CGRectMake(width,rearViewFrame.origin.y,rearViewFrame.size.width,rearViewFrame.size.height);
            _contentViewController.view.frame = CGRectMake(0, 0, width, _contentViewController.view.frame.size.height);
            self.titleLabel.alpha = 1;
        } completion:^(BOOL finished){
            _rearViewController.view.hidden = finished;
            self.navigationItem.rightBarButtonItem.enabled = TRUE;
        }];
        [self updateContentViewController];
    }
    }
    
     - (void)updateContentViewController
     {
         UIViewController *newVC = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%@VC",_rearViewController.selectedSection]];
         if([newVC class] == [ScoresViewController class])
         {
             if([_contentViewController  class] == [ScoresViewController class] &&
           [((ScoresViewController *) _contentViewController) date] != _rearViewController.datePicker.date)
             {
                 ((ScoresViewController *) newVC).date = _rearViewController.datePicker.date;
                 [self cycleToViewController:newVC];
             }
         }
         if([newVC class] != [_contentViewController class])
         {
             [self cycleToViewController:newVC];
         }
     }
    

    【讨论】:

    • 什么是_rearViewController听?
    【解决方案2】:

    请参阅下面的链接,其中包含很多示例

    Code4App Menu

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 2013-11-27
      • 2015-05-27
      • 2014-09-15
      • 1970-01-01
      • 1970-01-01
      • 2018-07-21
      相关资源
      最近更新 更多