我有一个与 iPhone 和 iPad 布局兼容的应用程序。对于 iPhone 布局,我为 iPad 创建了 Action Sheet 和 Pop over。问题是弹出箭头没有指向我单击的按钮。下面是我的代码....
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)
最佳答案
将sourceView
和sourceRect
设置为button
和button.bounds
。
您可以根据 View 的布局选择 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;
关于ios - 弹出不指向按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27823211/