如何使 UIsplitview 的弹出窗口在纵向模式 iPad 中可见

发布于 2024-09-17 05:42:48 字数 96 浏览 2 评论 0原文

我希望每当用户在 iPad 的 UIsplitView 中从横向视图切换到纵向视图时,弹出窗口视图就可见。虽然用户可以通过单击栏按钮使其可见,但我希望在纵向模式下自动执行此操作。

I would like to make popover view visible whenever user switches from landscape view to portrait view in UIsplitView of iPad. Although user can make it visible by clicking on bar button but I want this to be automated for portrait mode.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

俯瞰星空 2024-09-24 05:42:48

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

一切顺利。

Inside " -(BOOL) shouldAutorotateToInterfaceOrientation" method, check for the device orientation.If it is portrait, then Present the popover as you do for making it visible when user clicks bar button.

All the best.

我喜欢麦丽素 2024-09-24 05:42:48

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

UISplitViewController sends messages to his delegate (UISplitViewControllerDelegate). You can implement this delegate methods to show the popover. You can do something like this in your "detail controller" code:

#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;
}
帅气称霸 2024-09-24 05:42:48

接受的答案(使用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 中调用它来处理启动。

The accepted answer (using shouldAutorotateToInterfaceOrientation) doesn't work for me. It either has rotation artifacts (in the 4.2 and 5.0 iPad simulators) or only shows at startup and never again in subsequent rotations (the 4.3 simulator). What I did instead was to create a little helper function:

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

and call this within - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation and - (void)viewDidLoad to also handle on startup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文