简体   繁体   English

UISplitViewController中的ActionSheet在纵向模式下的行为与横向模式不同

[英]ActionSheet within UISplitViewController acts different in Portrait Mode than Landscape Mode

I created a new application using the Split View-based Application template. 我使用基于拆分视图的应用程序模板创建了一个新应用程序。

I then added an Action Button to the rootViewController navigation controller called actionButton. 然后我将一个Action Button添加到名为actionButton的rootViewController导航控制器中。

When the button is pressed, I display an ActionSheet like this: 按下按钮时,我会显示如下的ActionSheet:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
    delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
    otherButtonTitles:@"Admin Functions", @"Refresh Data", nil];
[actionSheet showFromBarButtonItem:actionButton animated:YES];
[actionSheet release];

After I press the button when in landscape mode it displays the action sheet in a popover which is pointing to the button (as I expected it to): 在横向模式下按下按钮后,它会在指向按钮的弹出框中显示操作表(正如我预期的那样):

景观模式

However, in Portrait mode it looks completely different and the menu comes up from the bottom of the rootViewController popover just like it does on the iPhone: 但是,在纵向模式下,它看起来完全不同,菜单从rootViewController popover的底部出现,就像在iPhone上一样:

肖像模式

My question is, how do I make the ActionSheet appear at the top while in portrait mode, just like it does when in landscape mode? 我的问题是,如何在纵向模式下使ActionSheet显示在顶部,就像在横向模式下一样?

Since this is a "utility menu", it isn't really tied directly to the data being displayed so it shouldn't be part of the popover. 由于这是一个“实用程序菜单”,它并不直接与显示的数据绑定,因此它不应该是弹出窗口的一部分。

This behaviour is by design, if it were a popover in portrait mode you would then have 2 levels of popover. 这种行为是设计的,如果它是纵向模式的弹出窗口,那么你将有2个级别的弹出窗口。

This is technically possible by implementing your own version of UIPopover or using one someone has already written ( WEPopover ). 这在技术上可以通过实现您自己的UIPopover版本或使用已经写过的人( WEPopover )来实现。

However, this is a poor design choice. 然而,这是一个糟糕的设计选择。 You say that the functions aren't related to the data, however one is 'refresh data'. 您说这些功能与数据无关,但其中一个是“刷新数据”。 I would replace the action button with a refresh icon such as the one Apple uses in 'Find my Friends': 我会用一个刷新图标替换动作按钮,例如Apple在“查找我的朋友”中使用的图标:

刷新按钮

The other, 'Admin Functions', if not directly related to the data in the list, perhaps needs a new home, maybe with the main view of your app? 另一方面,“管理功能”,如果不与列表中的数据直接相关,可能需要一个新的家,也许需要你的应用程序的主视图? It's hard to say where is best to put it without knowing more about the structure. 在不了解更多结构的情况下,很难说最好放在哪里。

Another possibility is that you could move the action button from right edge of the root view controller's bar to the left edge of the detail view controller's bar. 另一种可能性是您可以将操作按钮从根视图控制器栏的右边缘移动到详细视图控制器栏的左边缘。

For example, if the action button were located just to the right of the vertical bar in your first screen shot (meaning it's at the left edge of the detail view controller's bar), then when you rotate to portrait mode it would appear just to the right of the Events button in your second screen shot. 例如,如果操作按钮位于第一个屏幕截图中垂直条的右侧(意味着它位于详细视图控制器栏的左边缘),那么当您旋转到纵向模式时,它将仅显示在第二个屏幕截图中“事件”按钮的右侧。 You could still call UIActionSheet's showFromBarButtonItem:animated method, which would display your action sheet in popup mode. 您仍然可以调用UIActionSheet的showFromBarButtonItem:animated方法,它将以弹出模式显示您的操作表。

There's still the question of whether you really want two popovers on the screen at the same time. 还有一个问题是你是否真的想在屏幕上同时使用两个弹出窗口。 But if you do, this is how to do it. 但如果你这样做,这就是怎么做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM