ios - 弹出不指向按钮

标签 ios ipad swift popover

我有一个与 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)

最佳答案

sourceViewsourceRect 设置为buttonbutton.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/

相关文章:

ios - 文档关闭后调用 Swift UIDocument 自动保存且类未取消初始化

objective-c - CoreData 对象无法识别 BOOL 值

ios - Firebase 数据库 - 检查现有用户

ios - 奇怪的 UITableView 错误 : "Assertion Failure" on dequeuing static cells in storyboard

ios - 关闭双模式呈现 View Controller 的父 View Controller

xcode - 仅限 iPad 方向纵向

javascript - iOS5 Safari : Keyboard does not hide in a home screen HTML app

ios - 我如何知道 iPad 上何时出现拆分窗口拖动 handle ?

swift - 不同的 segues 转到相同的 ui View 而不是不同的 View

iOS 应用程序评论 - 视频流 MPEG-DASH 时间超过 10 分钟