UIPopover contentSize在运行时更改

问题描述 投票:3回答:1

我们面临的一个问题是,当在弹出框内使用alertController的UIActionSheet样式时,弹出框的大小将发生更改。这是在我们升级代码库iOS13之后发生的

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

ios ios13 uialertcontroller uiactionsheet
1个回答
-1
投票

我认为这是Apple的错误。我在Xcode 11.1上遇到过这种情况,但是在显示ActionSheet时在Xcode 11.2.1上却遇到了崩溃:

***由于未捕获的异常'NSGenericException'而终止应用程序,原因:'您的应用程序呈现了UINavigationController()的UIAlertControllerStyleActionSheet样式的UIAlertController()。具有此样式的UIAlertController的modalPresentationStyle为UIModalPresentationPopover。您必须通过警报控制器的popoverPresentationController提供此弹出窗口的位置信息。您必须提供sourceView和sourceRect或barButtonItem。如果在显示警报控制器时不知道此信息,则可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供它。'

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

Apple文档:

在iPad上,UIKit要求您在弹出框内显示操作表。

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

© www.soinside.com 2019 - 2024. All rights reserved.