2

我有一个在 iPhone 模拟器上运行良好的 UIActionSheet。它在用户触摸 UIButton 时呈现。

使用 iPad,我相信 UIActionSheets 被包装到 UIPopupController 中。

当我使用 iPad 模拟器调用相同的代码时,会显示一条细“线”,它看起来像 UIPopupController(您可以看到通常指向控件的小箭头)。看不到任何内容。

使用带有 MonoTouch 的 iPad 使用 UIActionSheet 的正确方法是什么?这是我一直在测试的一些示例代码 - 创建 UIActionSheet:

var actionSheet = new UIActionSheet () { Style = UIActionSheetStyle.BlackTranslucent };
        actionSheet.Frame = actionSheetFrame;
        actionSheet.Clicked += (s, e) => { Console.WriteLine ("Clicked on item {0}", e.ButtonIndex); };
actionSheet.AddSubview (doneButton);

然后,我通过从按钮调用以下命令来显示操作表:

btnSay.TouchUpInside += (sender, e) => {
            actionSheet.ShowFrom(tmpBtn.Frame, tmpView, false);
        };

使用 iPad 模拟器时,我得到了类似于所附屏幕截图的内容。

iPad UIActionSheet 示例

作为参考,这是使用 iPhone 模拟器时 UIActionSheet 的外观。

iPhone UIActionSheet 示例

注意:该项目是一个通用的单视图 MonoTouch c# 项目。

任何指示或帮助将不胜感激!

4

1 回答 1

6

我最近发布到应用商店的应用程序也遇到了同样的问题。

当您UIActionSheet在 iPad 上显示 a 时,iOSUIActionSheet会将UIPopoverView.

我用下面的代码来检测这是否是iPad,如果是,调整popover view的frame:

const int CHROMEWIDTHLEFT = 9;
const int CHROMEWIDTHRIGHT = 8;
const int MARGIN = 50;

UIActionSheet _actionSheet;

...

if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
    var popover = _actionSheet.Superview.Superview;
    if (popover != null)
    {
        var x = _actionSheet.Frame.X + MARGIN;
        var y = (UIScreen.MainScreen.ApplicationFrame.Height - _actionSheet.Frame.Height) / 2;
        var width = _actionSheet.Frame.Width - (MARGIN * 2);
        var height = _actionSheet.Frame.Height;

        popover.Frame = new RectangleF (x, y, width, height);
        _actionSheet.Frame = new RectangleF (x, y, width - (CHROMEWIDTHLEFT + CHROMEWIDTHRIGHT), height - (CHROMEWIDTHLEFT + CHROMEWIDTHRIGHT));
    }
}

该示例基于此处的 Xamarin ActionSheet 日期选择器

我把这些作为一个要点(Normal 和 DatePicker)

于 2012-11-11T01:35:00.410 回答