Sru*_*mha 24 popover ipad ios swift
我有一个兼容iPhone和iPad布局的应用程序.对于iPhone布局,我创建了Action Sheet和Pop over 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)
Run Code Online (Sandbox Code Playgroud)
rak*_*hbs 93
设置sourceView和sourceRect作为button和button.bounds.
您可以根据视图的布局选择allowedArrowDirections.
actionSheet.popoverPresentationController?.sourceView = button
actionSheet.popoverPresentationController?.sourceRect = button.bounds;
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Left;
Run Code Online (Sandbox Code Playgroud)
如果按钮是BarButtonItem,请使用此代码.
actionSheet.popoverPresentationController?.barButtonItem = button
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Up;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16833 次 |
| 最近记录: |