1

我正在关注有关在 iPad 处于纵向时隐藏拆分视图左侧的演示,然后在按下放置在工具栏中的按钮时将其显示为弹出框。我一步一步地跟着一切,它工作(有点)除了当我按下按钮时,而不是在弹出窗口中,视图显示从左到右滑动。我还注意到,我可以通过从左向右滑动手指而不是按下按钮来获得相同的结果。这是我使用的代码(相同的代码在演示中正常工作)。

在应该在 Popover 中显示的视图的视图控制器中:

-(BOOL)splitViewController:(UISplitViewController*)svc
  shouldHideViewController:(UIViewController*)vc
             inOrientation:(UIInterfaceOrientation)orientation
{
    return [self splitViewBarButtonItemPresenter] ? UIInterfaceOrientationIsPortrait(orientation) : NO;
}

-(void)splitViewController:(UISplitViewController *)svc
    willHideViewController:(UIViewController *)aViewController
         withBarButtonItem:(UIBarButtonItem *)barButtonItem
      forPopoverController:(UIPopoverController *)pc
{
    barButtonItem.title = self.title;
    [self splitViewBarButtonItemPresenter].splitViewBarButtonItem = barButtonItem;
}

-(void)splitViewController:(UISplitViewController *)svc
    willShowViewController:(UIViewController *)aViewController
 invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    [self splitViewBarButtonItemPresenter].splitViewBarButtonItem = nil;
}

在应该显示弹出框的视图中:

-(void)setSplitViewBarButtonItem:(UIBarButtonItem *)splitViewBarButtonItem
{
    if (_splitViewBarButtonItem != splitViewBarButtonItem){
        NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
        if (_splitViewBarButtonItem) [toolbarItems removeObject:_splitViewBarButtonItem];
        if (splitViewBarButtonItem) [toolbarItems insertObject:splitViewBarButtonItem atIndex:0];
        self.toolbar.items = toolbarItems;
        _splitViewBarButtonItem = splitViewBarButtonItem;
    }
}

SplitViewBarButtonItemPresenter只是一个协议,用于委托谁应该显示(你猜对了!)弹出框的按钮。

4

0 回答 0