我有一个正在使用的UIPopoverController
,并且有两个按钮,每个按钮在单击时都会显示一个弹出窗口。但是,我不希望同时显示弹出窗口-意味着我不希望用户能够按下一个按钮,而在显示弹出窗口时却能够按下另一个按钮。似乎我已经尝试了所有方法-禁用按钮上的用户交互,将视图隐藏在弹出窗口后面,对弹出窗口使用传递视图等等。没有一个有效!禁用用户交互似乎在大多数情况下都起作用,但是随后停止禁止用户与按钮交互,并导致应用程序崩溃...
popupView.PassthroughViews = new UIView[]{this.View.Superview, this.View, this.Gray}; //gray is another view that sits under the view that calls the popup
this.View.UserInteractionEnabled = false;
this.PositiveMeterBtn.UserInteractionEnabled = false;
this.View.Hidden = true;
我的
UIPopoverController
在类级别声明,我什至已经完成了如下代码:if(popupView != null)
return;
我仍然会看到多个弹出窗口。我正在使用mono touch / xamarin-这是xamarin的错误还是ios问题?我是否以正确的方式处理此问题?
最佳答案
您可以将弹出窗口设为有模式的,但如果其中不包含本来是有模式的内容,则不应阻止用户。
通常,更好的选择是制作两个帮助器方法,并将其放置在您的应用程序委托中。如果要显示另一个弹出窗口,则该方法应确保消除现有的弹出窗口。这样,您最多可以打开UIPopoverController
,而不必担心解雇。
/// <summary>
/// Shows a popover.
/// </summary>
/// <param name='controllerToShow'>the controller to show in the popover</param>
/// <param name='showFromRect'>the rectangle to present the popover from. Not used if showFromItem is specified.</param>
/// <param name='showInView'>the view the popover is hosted in</param>
/// <param name='showFromItem'>the bar button item the popover gets presented from.</param>
/// <param name='popoverContentSize'>the content size of the popover</param>
/// <param name='animated'>If set to <c>true</c>, animated the popover</param>
/// <param name='arrowDirection'>the allowed arrow directions</param>
/// <param name='onDismiss'>callback if the popover gets dismissed. Careful that the object that owns the callback doesn't outlive the popover controller to prevent uncollectable memory.</param>
public static void ShowPopover(UIViewController controllerToShow, RectangleF showFromRect, UIView showInView, UIBarButtonItem showFromItem, SizeF popoverContentSize, bool animated = true, UIPopoverArrowDirection arrowDirection = UIPopoverArrowDirection.Any, EventHandler onDismiss = null)
{
if(AppDelegateBase.popoverController != null)
{
AppDelegateBase.DismissPopover(false);
}
if(showFromItem == null && showFromRect.IsEmpty)
{
// Nothing to attach the popover to.
return;
}
popoverController = new UIPopoverController(controllerToShow);
if(!popoverContentSize.IsEmpty)
{
popoverController.SetPopoverContentSize(popoverContentSize, false);
}
if(onDismiss != null)
{
popoverController.DidDismiss += onDismiss;
}
// Send a notification that a popover will be presented.
NSNotificationCenter.DefaultCenter.PostNotificationName("WillPresentPopover", popoverController);
if(showFromItem != null)
{
popoverController.PresentFromBarButtonItem(showFromItem, arrowDirection, animated);
}
else
{
popoverController.PresentFromRect(showFromRect, showInView, arrowDirection, animated );
}
}
/// <summary>
/// Dismisses the popover presented using ShowPopover().
/// </summary>
/// <param name='animated'>If set to <c>true</c>, animates the dismissal</param>
public static void DismissPopover(bool animated = false)
{
if(popoverController != null)
{
popoverController.Dismiss(animated);
}
AppDelegateBase.popoverController = null;
}
private static UIPopoverController popoverController;
关于c# - 如何在uipopovercontroller后面的 View 上不允许交互,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19505300/