【问题标题】:UIActionSheet from Popover with iOS8 GM来自带有 iOS8 GM 的 Popover 的 UIActionSheet
【发布时间】:2014-11-03 18:37:01
【问题描述】:

有人在尝试从弹出窗口显示 UIActionSheet 时收到此消息?

您的应用程序呈现了一个 UIAlertController() 样式的 UIAlertControllerStyleActionSheet。具有此样式的 UIAlertController 的 modalPresentationStyle 是 UIModalPresentationPopover。您必须通过警报控制器的 popoverPresentationController 提供此弹出窗口的位置信息。您必须提供 sourceView 和 sourceRect 或 barButtonItem。如果在您呈现警报控制器时不知道此信息,您可以在 UIPopoverPresentationControllerDelegate 方法 -prepareForPopoverPresentation 中提供它。

在 GM 之前,我使用了一些解决方法将 UIActionSheet 转换为 UIAlertController,这工作正常。 然而,Apple 似乎试图解决 UIActionSheet 问题,而我不想使用我的解决方法 - 但似乎我别无选择......

【问题讨论】:

  • 您的意思是 UIAcitonsheet 已弃用但您仍想使用它???
  • 它已被弃用,但应该仍然可以工作......

标签: ios ios8 uipopovercontroller uiactionsheet uialertcontroller


【解决方案1】:

要支持 iPad,请包含以下代码:

alertView.popoverPresentationController?.sourceView = self.view
alertView.popoverPresentationController?.sourceRect = self.view.bounds
// this is the center of the screen currently but it can be any point in the view

self.presentViewController(alertView, animated: true, completion: nil)

【讨论】:

  • 什么是 shareMenu ?是 alertVc 吗?
  • @Misha,是的。这应该是 alertVC
【解决方案2】:

如果您在用户在UITableView 中的单元格上进行选择后显示操作表。我发现这很好用:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Directions" 
                                                               message:@"Select mode of transportation:"
                                                        preferredStyle:UIAlertControllerStyleActionSheet];
alert.popoverPresentationController.sourceView = cell;
alert.popoverPresentationController.sourceRect = cell.bounds;
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
//...
[self presentViewController:alert animated:YES completion:nil];

【讨论】:

    【解决方案3】:

    您需要提供popoverPresentationController 以获得 iPad 支持。在此,您可以指定barButtonItemsourceView。这另一个线程可能会对您有所帮助:Swift UIAlertController - ActionSheet iPad iOS8 Crashes

    【讨论】:

      【解决方案4】:

      实际上,目前 Xcode for iPhone 和 iPad 设计中存在一些问题(我相信)。

      1. 在 iPhone 中,相同的代码可以完美运行,您可以在相同的位置(始终)看到警报消息。但对于 iPad,您需要使用alert.popoverPresentationController.sourceView = self.view; alert.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0 - 105, self.view.bounds.size.height / 2.0 + 70, 1.0, 1.0); 定义警报框的位置,105 和 70 是 iPad 纵向设计由于锚点不同造成的近似尺寸差异。
      2. 在 iPhone 设计中UIAlertController 带有“模态视图”,但不幸的是,如果您在 iPad 上使用相同的代码,它将不是“模态视图”。这意味着您需要编写额外的代码来禁用 iPad 设计中的触摸。我觉得这很奇怪。
      3. 在 iPad 设计中,您需要考虑锚点的不同。它是气泡三角点,而不是 AlertView 的左上角。

      这些是我看到的奇怪的东西。我认为必须有一个标准,如果有人想出标准,可以,还有其他选择。

      【讨论】:

        【解决方案5】:

        UIAlertController 只是 iOS8,需要支持 iOS7,我正在使用它。我在 iPad 上的主/细节布局中的主视图上遇到了这个问题。我能够通过使用 [actionSheet showInView:] 从父 UISplitViewController 提升 UIActionSheet 来解决它(不完全修复它)。祝你好运。

        【讨论】:

          【解决方案6】:

          如果您想在 iPad 上和通常在 iPhone 上不带箭头的中心显示它:[Swift 3+]:

          if let popoverController = alertController.popoverPresentationController {
              popoverController.sourceView = self.view
              popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
              popoverController.permittedArrowDirections = []
          }
          self.present(alertController, animated: true, completion: nil)
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-02-15
            • 2014-03-06
            • 1970-01-01
            • 2016-03-11
            • 1970-01-01
            相关资源
            最近更新 更多