我有一个与iPhone和iPad布局都兼容的应用程序。对于iPhone布局,我已经为iPad创建了动作表和弹出窗口。问题是弹出的箭头没有指向我点击的按钮。下面是我的代码..。
let actionSheet = UIAlertController(title: "Choose an option",
message: "Message",
preferredStyle: .ActionSheet)
...
if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad
{
// for iPad
actionSheet.popoverPresentationController?.sourceView = self.view
actionSheet.popoverPresentationController?.sourceRect = self.view.bounds;
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.allZeros;
}
self.presentViewController(actionSheet, animated: true, completion: nil)
发布于 2015-01-08 00:10:11
将sourceView
和sourceRect
设置为button
和button.bounds
。
您可以根据视图的布局选择permittedArrowDirections。
actionSheet.popoverPresentationController?.sourceView = button
actionSheet.popoverPresentationController?.sourceRect = button.bounds;
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Left;
如果按钮是BarButtonItem,请使用以下代码。
actionSheet.popoverPresentationController?.barButtonItem = button
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Up;
发布于 2016-04-15 09:54:39
对我来说,使用发送器并将其转换为UIView。
alertController.popoverPresentationController?.sourceView = sender as! UIView
alertController.popoverPresentationController?.sourceRect = sender.bounds
alertController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Up
https://stackoverflow.com/questions/27823211
复制相似问题