使用Mvvmcross隐藏Xamarin项目中的导航栏

时间:2014-01-07 12:53:57

标签: xamarin.ios xamarin mvvmcross

我正在使用mvvmcross并在后面的代码中实现视图的接口。我想隐藏导航栏但我还没有找到解决方案。

我试过

NavigationController.SetNavigationBarHidden(true, false);

NavigationController.NavigationBarHidden = true;

使用不同的方法(ViewDidAppear和ViewWillAppear),但它们对UI没有影响。

也许有人可以给我一个提示。 : - )

@Edit:更多信息:

我的AppDelegate.cs

[Register("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
{
    UIWindow _window;

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        _window = new UIWindow(UIScreen.MainScreen.Bounds);

        var setup = new Setup(this, _window);
        setup.Initialize();

        var startup = Mvx.Resolve<IMvxAppStart>();
        startup.Start();

        _window.MakeKeyAndVisible();

        return true;
    }
}

此外,我正在使用一个继承自MvxViewController的BaseView类。

4 个答案:

答案 0 :(得分:6)

好的,我自己找到了解决方案:

只需将以下代码粘贴到MvxViewController类的ViewDidLoad方法中(例如许多mvvmcross教程中的FirstView.cs):

var navController = base.NavigationController;
navController.NavigationBarHidden = true;

答案 1 :(得分:1)

我知道这是一个已有6年历史的问题,但是遇到了使用MVVMCross为此问题找到解决方案的过程,发现在您的视图xaml中使用此解决方案就足够了:<NavigationPage.HasNavigationBar>False</NavigationPage.HasNavigationBar>

它应该同时适用于Xamarin Android和iOS。

答案 2 :(得分:0)

这会杀了它,如果你有疑问,请告诉我。

[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
    // class-level declarations
    UIWindow window;
    MyViewController viewController;
    MainViewController mainViewController;
    UINavigationController navController;

    public UINavigationController NavController { get { return navController; }}

    //
    // This method is invoked when the application has loaded and is ready to run. In this
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //
    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        var navController = new UINavigationController(); 
        navController.SetNavigationBarHidden (true, false);

        window = new UIWindow (UIScreen.MainScreen.Bounds); 
        viewController = new MyViewController();

        app.SetStatusBarStyle (UIStatusBarStyle.LightContent, true);

        navController.PushViewController(viewController, false);

        window.RootViewController = navController;
        window.MakeKeyAndVisible ();

        return true;
    }
}

}

答案 3 :(得分:0)

默认的演示者在窗口上为RootController使用UINavigationController;因此,您可以通过从窗口抓取并转换来全局操作AppDelegate中的导航栏:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    window = new UIWindow(UIScreen.MainScreen.Bounds);

    new Setup(this, window).Initialize();
    Mvx.Resolve<IMvxAppStart>().Start();

    var navigationBar = ((UINavigationController)window.RootViewController).NavigationBar;
    navigationBar.BackgroundColor = UIColor.Black;
    navigationBar.BarTintColor = UIColor.Black;
    navigationBar.TintColor = UIColor.White;

    window.MakeKeyAndVisible();

    return true;
}