MvvmCross iOS 没有插件的汉堡包菜单 iOS 本机

MvvmCross iOS hamburger Menu without plugins iOS Native

好的,这就是我想在 MvvmCross 中做的,没有任何插件,只有本机代码。我确实找到了关于如何操作的教程,但我想在 MvvmCross.iOS Have a look at what I would like to do in MvvmCross.iOS

中找到它

MvvmCross.iOS

请指教或转发更好的教程

要记住的要点

汉堡包菜单应该像我链接的图片一样具有可拖动效果

我试过的

ViewDidLoad() -->

UIPanGestureRecognizer gesture = new UIPanGestureRecognizer();


        gesture.AddTarget(() => HandleDrag(gesture));
        this.View.AddGestureRecognizer(gesture);

        panGestureRecognizer = new UIScreenEdgePanGestureRecognizer ( HandleSwipeRight);
        panGestureRecognizer.Edges = UIRectEdge.Left;
        this.View.AddGestureRecognizer(panGestureRecognizer);

HandleDrag() -->

        protected void HandleDrag(UIPanGestureRecognizer recognizer)
    {
        PointF offset2 = (System.Drawing.PointF)recognizer.TranslationInView(View);


        if (recognizer.State != (UIGestureRecognizerState.Cancelled | UIGestureRecognizerState.Failed
            | UIGestureRecognizerState.Possible))
        {
            Console.WriteLine("Here");
            // NEED TO LOAD ANOTHER VIEW HERE
            openMenu();

        }

    }

openMenu() -->

        public void openMenu()
    {
        viewBlack.Hidden = false;
        this.view.Hidden = false;
        UIView.Animate(
             duration: 0.3,
             delay: 0,
             options: UIViewAnimationOptions.CurveEaseInOut |
                 UIViewAnimationOptions.Autoreverse,
             animation: () =>
             {

            this.view.LayoutIfNeeded();
                 this.viewBlack.Alpha = this.maxBlackViewAlpha = 0.5f;
             },
             completion: () =>
             {
                 panGestureRecognizer.Enabled = false;
             }
        );
    }

隐藏菜单() -->

        public void closeMenu(){

        UIView.Animate(
    duration: 0.3,
    delay: 0,
    options: UIViewAnimationOptions.CurveEaseInOut |
        UIViewAnimationOptions.Autoreverse,
    animation: () =>
    {
            this.view.LayoutIfNeeded();
            this.viewBlack.Alpha = 0;
    },
    completion: () =>
    {
            panGestureRecognizer.Enabled = true;
            viewBlack.Hidden = true;
            view.Hidden = true;
    }
    );
    }

我的自定义汉堡包菜单 UIView -->

            view = new UIView();
        view.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width / 1.1, UIScreen.MainScreen.Bounds.Height);
        var gradientLayer = new CAGradientLayer();
        gradientLayer.Colors = new[] { UIColor.FromRGB(64, 0, 128).CGColor, UIColor.FromRGB(0, 0, 128).CGColor };
        gradientLayer.Locations = new NSNumber[] { 0, 1 };
        gradientLayer.Frame = view.Frame;
        view.BackgroundColor = UIColor.Clear;
        view.Layer.AddSublayer(gradientLayer);
        var viewline = new UIView();
        viewline.Frame = new CGRect(20, 60, 100, 1);
        viewline.BackgroundColor = UIColor.White;
        var bb = new UIBarButtonItem();
        var Allbutton = new UIButton(new CGRect(0, 20, 135, 20));
        Allbutton.SetTitleColor(UIColor.Black, UIControlState.Normal);
        Allbutton.TitleLabel.BackgroundColor = UIColor.White;
        Allbutton.SetTitle("Login", UIControlState.Normal);
        var myPrefbutton = new UIButton(new CGRect(0, 120, 135, 20));
        myPrefbutton.SetTitleColor(UIColor.Black, UIControlState.Normal);
        myPrefbutton.SetTitle("Logout", UIControlState.Normal);
        myPrefbutton.TitleLabel.BackgroundColor = UIColor.White;
        view.BackgroundColor = UIColor.White;
        view.Add(Allbutton);
        view.Add(viewline);
        view.Add(myPrefbutton);
        view.Hidden = true;
        this.View.AddSubviews(view);

这是我能够从教程 (SWIFT) 转换为 MvvmCross.iOS 的唯一代码,它可以工作,但是 我无法拖动菜单来显示,发生的事情是它正常加载并且速度很快

注意!!!我没有使用任何 Storyboards 或 nib 文件,只是使用这个汉堡菜单的纯代码

请仔细查看 .gif 文件,注意菜单是可拖动的,这使得它的动画速度慢而不快。

如果我让您感到困惑,请不要难过我才刚刚开始使用 iOS 和 MvvmCross 进行编码...我还是个菜鸟

成功了

首先必须创建一个 UIVew class -->

侧边菜单视图:MvxViewController

然后将 X 设置为减号...如果用户选择 navbaritem,它将为零我还添加了一个覆盖 UIView

        viewBlack = new UIView();
        viewBlack.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
        viewBlack.BackgroundColor = UIColor.Black;
        viewBlack.Alpha = 0.5f;
        viewBlack.Hidden = true;
        this.View.AddSubviews(viewBlack);