2013-10-21 38 views
0

我有我正在使用的UIPopoverController,並且我有兩個按鈕,每個按鈕在點擊時顯示一個彈出窗口。但是,我不希望彈出窗口同時顯示 - 這意味着我不希望用戶能夠按一個按鈕,並且顯示彈出窗口時能夠按下另一個按鈕。看起來我已經嘗試了一切 - 禁用按鈕上的用戶交互,隱藏彈出窗口後面的視圖,使用流行視圖和更多的傳遞視圖。它沒有任何作品!用戶交互的禁止,似乎大部分工作,但隨後停止不允許用戶與該按鈕交互,並會導致應用程序崩潰...如何禁止在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問題?我是否以正確的方式處理?

回答

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; 
2

我還沒有與Xamarin合作過,但什麼工作對我來說在本地的Objective-C是

[controller setModalInPopover:YES]; 

其中controller是酥料餅中顯示的視圖控制器。

從UIViewController類參考:

@屬性(非原子,讀寫,吸氣劑= isModalInPopover)BOOL modalInPopover

該屬性的缺省值是NO。將其設置爲YES會導致擁有的彈出窗口控制器在顯示時禁止該視圖控制器之外的交互。

+0

不認爲這是與Xamarin – jharr100

+0

選項從我可以在Xamarin論壇告知,該行代碼會看起來像'myController.ModalInPopover = TRUE;' – Kamaros

0

有一兩件事你可以嘗試使用方法

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

而且在這個方法檢查,如果你的酥料餅的視圖控制器之一就是在屏幕上。

if (popupView.view.window) { 
    return NO; 
} else { 
    return YES; 
} 
相關問題