示例#1
0
        public override void ShowTabView(UIViewController viewController, MvxTabPresentationAttribute attribute)
        {
            System.Type vcType;

            if (viewController is UINavigationController)
            {
                vcType = viewController.ChildViewControllers[0].GetType();
            }
            else
            {
                vcType = viewController.GetType();
            }

            var existingVc = ChildViewControllers.FirstOrDefault(x =>
            {
                if (x is UINavigationController)
                {
                    return(x.ChildViewControllers[0].GetType() == vcType);
                }
                else
                {
                    return(x.GetType() == vcType);
                }
            });

            if (existingVc != null && ChildViewControllers != null)
            {
                SelectedIndex = Array.IndexOf(ChildViewControllers, existingVc);
            }
            else
            {
                base.ShowTabView(viewController, attribute);
            }
        }
示例#2
0
        public void SetViewController(UIViewController vc, bool animated)
        {
            //dont activate new vc instance of same type
            var target = ChildViewControllers.FirstOrDefault();

            if (target != null)
            {
                if (target.GetType() == vc.GetType())
                {
                    return;
                }
            }


            vc.View.TranslatesAutoresizingMaskIntoConstraints = false;

            if (animated)
            {
                UIView.Transition(View, 1.0, UIViewAnimationOptions.CurveEaseOut, () =>
                {
                    View.Subviews?.ToList().ForEach(p => p.RemoveFromSuperview());
                    ChildViewControllers?.ToList().ForEach(p => p.RemoveFromParentViewController());

                    AddChildViewController(vc);
                    View.AddSubview(vc.View);
                    View.AddConstraint(NSLayoutConstraint.Create(vc.View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 0));
                    View.AddConstraint(NSLayoutConstraint.Create(vc.View, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, 0));
                    View.AddConstraint(NSLayoutConstraint.Create(vc.View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0));
                    View.AddConstraint(NSLayoutConstraint.Create(vc.View, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 0));
                }, null);
            }
            else
            {
                View.Subviews?.ToList().ForEach(p => p.RemoveFromSuperview());
                ChildViewControllers?.ToList().ForEach(p => p.RemoveFromParentViewController());

                AddChildViewController(vc);
                View.AddSubview(vc.View);
                View.AddConstraint(NSLayoutConstraint.Create(vc.View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 0));
                View.AddConstraint(NSLayoutConstraint.Create(vc.View, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, 0));
                View.AddConstraint(NSLayoutConstraint.Create(vc.View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0));
                View.AddConstraint(NSLayoutConstraint.Create(vc.View, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 0));
            }

            ActiveViewController = vc;
        }