ios - UIPopover contentSize 在运行时发生变化

标签 ios ios13 uialertcontroller uiactionsheet

我们面临一个问题,即当弹出窗口内使用 UIActionSheet 样式的alertController 时,弹出窗口大小会发生变化。这是在我们升级代码库 iOS13 后发生的

示例代码:https://github.com/Sundeep-manne/UIPopover.git

最佳答案

我认为这是苹果的错误。 我在 Xcode 11.1 上体验过它,但在 Xcode 11.2.1 上显示 ActionSheet 时出现崩溃:

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController () of style UIAlertControllerStyleActionSheet from UINavigationController (). The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'

所以答案是:要在 iPad 上使用 ActionSheet,您需要在 UIAlertController 的 popoverPresentationController 中提供 sourceView 和 sourceRect。更多信息: https://medium.com/@nickmeehan/actionsheet-popover-on-ipad-in-swift-5768dfa82094

苹果文档:

On iPad, UIKit requires that you display an action sheet inside a popover.

https://developer.apple.com/documentation/uikit/windows_and_screens/getting_the_user_s_attention_with_alerts_and_action_sheets

关于ios - UIPopover contentSize 在运行时发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58008997/

相关文章:

swift - TabView 的 TabItem 的选定选项卡图像在 SwiftUI 中始终为蓝色

ios - 在 SWIFT 4 中将文本字段限制为仅正整数

ios - UIAlert Controller 上的图标

iphone - Sybase ULtralite DB 和 iOS 核心数据

iphone - 在 iOS 应用程序中向下滚动时自动加载数据

ios - ScrollView 中的 SwiftUI 动画不起作用

AlertController 内的 Html 文件?

ios - 尽管 faSTLane beta 表示构建已上传到 Crashlytics,但没有在 Fabric 中创建新应用

ios - UICollectionView 中的 IBOutlets 为 nil - Swift

swift - 防止解除 UIAlertController