1

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

MyUIPopoverController在类级别声明,我什至完成了这样的代码:

if(popupView != null)
    return;

我仍然收到多个弹出窗口。我正在使用单声道触摸/xamarin - 这是 xamarin 的错误还是 ios 问题?我是否以正确的方式处理这个问题?

4

3 回答 3

2

我以前没有使用过 Xamarin,但是在原生 Objective-C 中对我有用的是

[controller setModalInPopover:YES];

controller弹出窗口中显示的视图控制器在哪里。

从 UIViewController 类参考:

@property(nonatomic, readwrite, getter=isModalInPopover) BOOL modalInPopover

此属性的默认值为 NO。将其设置为 YES 会导致拥有的弹出框控制器在显示时禁止该视图控制器之外的交互。

于 2013-10-22T03:10:11.953 回答
1

您可以将弹出框设为模态,但如果它不包含应为模态的内容,则不应阻止用户。

通常更好的选择是创建两个辅助方法并将它们放置在您的应用程序委托中。如果要显示另一个弹出框,这些方法会注意关闭现有的弹出框。这样,您将拥有最多的开启时间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;
于 2013-10-22T06:53:21.713 回答
0

您可能会尝试的一件事是使用该方法

-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender

并在该方法中检查您的弹出视图控制器之一是否在屏幕上。

if (popupView.view.window) {
    return NO;
} else {
    return YES;
}
于 2014-04-03T01:10:20.630 回答