5

每当用户在 iPad 的 UIsplitView 中从横向视图切换到纵向视图时,我想让弹出视图可见。虽然用户可以通过单击栏按钮使其可见,但我希望这对于纵向模式是自动化的。

4

3 回答 3

4

在“ -(BOOL) shouldAutorotateToInterfaceOrientation”方法中,检查设备方向。如果是纵向,则像您一样呈现弹出框,以便在用户单击栏按钮时使其可见。

祝一切顺利。

于 2010-09-27T12:52:03.623 回答
2

UISplitViewController 向他的委托 (UISplitViewControllerDelegate) 发送消息。您可以实现此委托方法来显示弹出框。您可以在“详细控制器”代码中执行以下操作:

#pragma mark -
#pragma mark UISplitViewControllerDelegate implementation
- (void)splitViewController:(UISplitViewController*)svc 
     willHideViewController:(UIViewController *)aViewController 
          withBarButtonItem:(UIBarButtonItem*)barButtonItem 
       forPopoverController:(UIPopoverController*)pc
{  
    [barButtonItem setTitle:@"Your 'popover button' title"];
    self.navigationItem.leftBarButtonItem = barButtonItem;
}


- (void)splitViewController:(UISplitViewController*)svc 
     willShowViewController:(UIViewController *)aViewController 
  invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    self.navigationItem.leftBarButtonItem = nil;
}
于 2011-02-25T17:33:13.060 回答
1

接受的答案(使用shouldAutorotateToInterfaceOrientation)对我不起作用。它要么具有旋转工件(在 4.2 和 5.0 iPad 模拟器中),要么仅在启动时显示,并且在随后的旋转中不再显示(4.3 模拟器)。我所做的是创建一个小辅助函数:

- (void)showPopoverInPortrait {
    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
        [self.masterPopoverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem
                                             permittedArrowDirections:UIPopoverArrowDirectionAny 
                                                             animated:YES];
    }
}

并在启动时调用它- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation- (void)viewDidLoad处理。

于 2011-12-02T08:55:18.467 回答