弹出窗口没有指向按钮 [英] Pop over doesn't point over the button
本文介绍了弹出窗口没有指向按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序兼容iPhone和iPad布局。对于iPhone布局,我已经创建了Action Sheet和Pop over iPad。问题是弹出箭头没有指向我点击的按钮。下面是我的代码....
I have an application that is compatible with both iPhone and iPad layouts. For iPhone layout I have created Action Sheet and Pop over for iPad. The problem is pop over's arrow does not point over the button I clicked. Below is my code....
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.bounds
。
您可以根据视图的布局选择allowedArrowDirections。
Set the sourceView
and sourceRect
as the button
and button.bounds
.
You can choose the permittedArrowDirections depending on the layout of your view.
actionSheet.popoverPresentationController?.sourceView = button
actionSheet.popoverPresentationController?.sourceRect = button.bounds;
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Left;
如果按钮是BarButtonItem,请使用此代码。
If the button is a BarButtonItem use this code.
actionSheet.popoverPresentationController?.barButtonItem = button
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Up;
这篇关于弹出窗口没有指向按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文