[英]UIActionSheet from Popover with iOS8 GM
Anyone is getting this message while trying to show UIActionSheet from popover? 尝试从popover显示UIActionSheet时,是否有人收到此消息?
Your application has presented a UIAlertController () of style UIAlertControllerStyleActionSheet. 您的应用程序提供了样式UIAlertControllerStyleActionSheet的UIAlertController()。 The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. 具有此样式的UIAlertController的modalPresentationStyle是UIModalPresentationPopover。 You must provide location information for this popover through the alert controller's popoverPresentationController. 您必须通过警报控制器的popoverPresentationController为此弹出窗口提供位置信息。 You must provide either a sourceView and sourceRect or a barButtonItem. 您必须提供sourceView和sourceRect或barButtonItem。 If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation. 如果在显示警报控制器时未知此信息,则可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供该信息。
Previously to the GM I used some workaround for converting the UIActionSheet to UIAlertController and this is working fine. 在GM之前,我使用了一些解决方法将UIActionSheet转换为UIAlertController,这很好用。 However it seems that Apple tried to solve the UIActionSheet issues and I didn't want to use my workaround - but it seems that I have no choice... 然而,似乎Apple试图解决UIActionSheet问题,我不想使用我的解决方法 - 但似乎我别无选择......
To support iPad, include this code: 要支持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)
If you are presenting the action sheet after the user makes a selection on a cell within a UITableView
. 如果您在用户对UITableView
的单元格进行选择后显示操作表。 I found that this works decently well: 我发现这个效果很好:
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];
You need to provide popoverPresentationController
for iPad support. 您需要提供popoverPresentationController
以支持iPad。 In this, you either specify barButtonItem
or sourceView
. 在此,您可以指定barButtonItem
或sourceView
。 This another thread may help you: Swift UIAlertController - ActionSheet iPad iOS8 Crashes 这个另一个线程可以帮到你: Swift UIAlertController - ActionSheet iPad iOS8崩溃
Actually it is something buggy (I believe) in Xcode for iPhone and iPad designs for now. 实际上,对于iPhone和iPad设计来说,这是Xcode中的一些错误(我相信)。
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);
但对于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);
定义警报框的位置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);
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 and 70 are the approximate dimension differences for iPad portrait design due to different anchor point. 105和70是由于不同的锚点而导致的iPad肖像设计的近似尺寸差异。 UIAlertController
comes with 'Modal View' but unfortunately if you use same code for iPad it will not be a 'Modal View'. 在iPhone设计中, UIAlertController
带有'Modal View'但不幸的是,如果你在iPad上使用相同的代码,它将不会是'模态视图'。 Which means that you need to write extra code for disabling touches in iPad design. 这意味着您需要编写额外的代码来禁用iPad设计中的触摸。 I think it is weird. 我认为这很奇怪。 These are the weird things I see. 这些是我看到的奇怪的事情。 I think that there must be a standard and if someone wants to go out standards, fine, there can be other options. 我认为必须有一个标准,如果有人想要出标准,那么可以有其他选择。
UIAlertController being iOS8 only, and needing to support iOS7, I am using it. UIAlertController只是iOS8,需要支持iOS7,我正在使用它。 I ran into this on a Master view in a Master/Detail layout on iPad. 我在iPad上的主/细节布局中的主视图上遇到了这个问题。 I was able to work around it (not exactly fix it) by raising the UIActionSheet from the parent UISplitViewController using [actionSheet showInView:]. 通过使用[actionSheet showInView:]从父UISplitViewController引发UIActionSheet,我能够解决它(不完全修复它)。 Good luck. 祝好运。
If you want to present it in the centre with no arrows on iPads and normally on iPhones: [ Swift 3+ ]: 如果你想把它放在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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.