Forum Xamarin Xamarin.iOS

Monogame shows navigationbar but it is not clickable

Hey all

So like the question says I have a monogame and on top of it I have my iOS navigation bar. The navigation shows but the problem is that I can't click on the buttons of the navigationbar. So I was wondering if the navigationbar is behind the monogame. The monogame itself is the default game with just a background. I tried using this in my code.

 public override void FinishedLaunching(UIApplication app)
        {
            game = new Game1();
            game.Run();
            window = new UIWindow(UIScreen.MainScreen.Bounds);
            navigationRenderer = new NavigationRenderer();
            controller = new UINavigationController(navigationRenderer);
            var gameController = game.Services.GetService(typeof(UIViewController)) as UIViewController;

            //window = (UIWindow)game.Services.GetService(typeof(UIWindow));

            controller.NavigationBar.BackgroundColor = UIColor.Brown;
            controller.SetNavigationBarHidden(false, true);
            window.RootViewController = controller;
            if (gameController != null) gameController.View.AddSubview(controller.View);

            //controller.View.AddSubview(gameController.View);

            window.MakeKeyAndVisible();

        }

But it doesn't seem to work. Below is my code for my custom navigationcontroller. I am a newbie so if there are some things you guys won't do feel free to tell me!

 internal class NavigationRenderer : UIViewController
    {
        private string _selectedOption;
        List<object> state_list = new List<object> { "Horizontal", "Vertical" };

        public NavigationRenderer() : base()
        {

        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            UITextView stateTextView = new UITextView();
            UITextView gameOptionTextView = new UITextView();


            UIBarButtonItem[] items = {
                new UIBarButtonItem(
                    NSBundle.MainBundle.LocalizedString("Home", null),
                    UIBarButtonItemStyle.Bordered,
                    delegate
                    {
                        // do whatever you need
                        Console.WriteLine("Custom button clicked!");
                    }),
                new UIBarButtonItem(SetupPicker(state_list,stateTextView)),
                new UIBarButtonItem(SetupPicker(gameOptionTextView)), 
                new UIBarButtonItem(
                    NSBundle.MainBundle.LocalizedString("Graph", null),
                    UIBarButtonItemStyle.Bordered,
                    delegate
                    {
                        //this.DismissViewController(true,null);
                    })
            };


            //NavigationController.NavigationBar.TintColor = UIColor.FromRGBA(255, 196, 196, 255);
            NavigationItem.LeftBarButtonItems = items;
        }

        public override void ViewDidAppear(bool animated)
        {
            NavigationController.NavigationBarHidden = false;

        }

        public override void ViewDidDisappear(bool animated)
        {
            NavigationController.NavigationBarHidden = true;
        }

        private UITextView SetupPicker(IList<object> list, UITextView textView)
        {
            PickerModel pickerModel = new PickerModel(list);

            pickerModel.PickerChanged += (sender, e) =>
            {
                _selectedOption = e.SelectedValue;
            };

            var picker = new UIPickerView
            {
                Model = pickerModel,
                ShowSelectionIndicator = true
            };

            textView = new UITextView(new RectangleF(10, 100, 60, 30))
            {
                //Editable = false
            };


            UIToolbar toolbar = new UIToolbar
            {
                BarStyle = UIBarStyle.Default,
                Translucent = true
            };
            toolbar.SizeToFit();

            UIBarButtonItem doneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, (s, e) =>
            {
                //This dismisses the picker view and returns control to the main screen.
                textView.ResignFirstResponder();
                textView.Text = _selectedOption;
                _selectedOption = "";
            });

            toolbar.SetItems(new[] { doneButton}, true);

            textView.InputAccessoryView = toolbar;
            textView.InputView = picker;

            return textView;
        }

        private UITextView SetupPicker(UITextView textView)
        {
            //var pickerModel = new PickerModelWithImages(list, images);
            var pickerModel = new CustomPickerModel();

            pickerModel.PickerChanged += (sender, e) =>
            {
                _selectedOption = e.SelectedValue;
            };

            var picker = new UIPickerView
            {
                Model = pickerModel,
                ShowSelectionIndicator = true
            };

            textView = new UITextView(new RectangleF(10, 100, 60, 30))
            {
                Editable = false
            };

            UIToolbar toolbar = new UIToolbar
            {
                BarStyle = UIBarStyle.Default,
                Translucent = true
            };
            toolbar.SizeToFit();

            UIBarButtonItem doneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, (s, e) =>
            {
                //This dismisses the picker view and returns control to the main screen.
                textView.ResignFirstResponder();
                textView.Text = _selectedOption;
            });

            toolbar.SetItems(new[] { doneButton }, true);

            textView.InputAccessoryView = toolbar;
            textView.InputView = picker;

            return textView;
        }
    }

I also tried to resize the monogame but that also doesn't seem to work. And I don't know why. I searched a lot about this problem. But can't seem to find the right answer. I tried the answers from here: http://stackoverflow.com/questions/11283294/how-to-resize-window-using-xna. But stilll no success.

Thanks

Best Answer

Answers

Sign In or Register to comment.