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

时间:2018-10-12 11:09:07

标签: c# ios xamarin xamarin.ios mvvmcross

What I would like

好的,这是我想在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;
             }
        );
    }

hideMenu()->

        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中进行编码...我仍然是菜鸟

1 个答案:

答案 0 :(得分:0)

让它正常工作

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

SideMenuView: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);