我試圖用這個component這example以實現Xamarin.iOS一個側面菜單。 一切工作正常,除了我想關閉側面菜單的部分。Sidemenu不打烊 - Xamarin.iOS
現在它的工作原理是這樣的:我可以通過使用NavigationItem中的LeftButton或手指滑動來打開側邊菜單。但我無法用這兩種方法中的任何一種來關閉它。
有沒有人知道爲什麼會發生這種情況?我錯過了什麼?
另請參閱下面的代碼。
HomeView
public partial class HomeView : MvxViewController
{
public HomeView() : base("HomeView", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
CGRect screenRect = UIScreen.MainScreen.Bounds;
NavigationController.View.Frame = new CGRect(0, 0, screenRect.Width, screenRect.Height);
var app = UIApplication.SharedApplication.Delegate as AppDelegate;
NavigationItem.SetLeftBarButtonItem(
new UIBarButtonItem(UIImage.FromBundle("menu"),
UIBarButtonItemStyle.Plain, (sender, e) =>
{
app.SidebarController.ToggleMenu();
}), true);
}
RootView
public partial class RootView : MvxViewController
{
public RootViewModel RootViewModel
{
get { return (RootViewModel)ViewModel; }
set { ViewModel = value; }
}
public RootView() : base("RootView", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
if (ViewModel == null)
return;
var app = UIApplication.SharedApplication.Delegate as AppDelegate;
app.SidebarController = new SidebarController(this,
CreateViewFor(RootViewModel.Home, false), CreateViewFor(RootViewModel.Menu, true));
app.SidebarController.MenuWidth = 220;
app.SidebarController.ReopenOnRotate = false;
app.SidebarController.MenuLocation = MenuLocations.Left;
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
private UIViewController CreateViewFor(IMvxViewModel viewModel, bool navBarHidden)
{
var controller = new UINavigationController();
var screen = this.CreateViewControllerFor(viewModel) as UIViewController;
controller.PushViewController(screen, false);
controller.NavigationBarHidden = navBarHidden;
return controller;
}
我不知道你的代碼有什麼問題。但是我在我的項目中使用了側欄導航,它工作得很好。如果你想,我可以發佈我的代碼 – HeisenBerg
你也用MVVMCross? –
當我繼續調查這一點時,我發現RootViewController位於其他兩個控制器(Menu和Home ViewControler)的頂部,並且它阻止了這兩者之間的所有交互/事件。 –