我们面临一个问题,即当弹出窗口内使用 UIActionSheet 样式的alertController 时,弹出窗口大小会发生变化。这是在我们升级代码库 iOS13 后发生的
最佳答案
我认为这是苹果的错误。 我在 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.
关于ios - UIPopover contentSize 在运行时发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58008997/