我试图用这个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)的顶部,并且它阻止了这两者之间的所有交互/事件。 –