c# - 没有插件的 MvvmCross iOS 汉堡菜单 iOS Native
问题描述
好的,这就是我想在 MvvmCross 中做的,没有任何插件,只是本机代码。我确实找到了有关如何使用它的教程,但我想在 MvvmCross.iOS 中找到它 看看我想在 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 类 -->
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);
推荐阅读
- git - 如何将远程分支合并到本地分支?
- python - Python:ValueError: scatter 需要 y 列为数字?
- java - 获取 org.apache.maven.plugins:maven-jar-plugin:2.3.2 或其依赖项之一无法解决错误
- c - 以某些数字打印数字
- python - “break”会杀死一个运行while循环的线程吗?
- python - 使用多列的 Pandas groupby 函数
- python-3.x - flask-sqlalchemy db.Model._decl_class_registry.values() 和 db.metadata.tables 不一致
- libgdx - libgdx 音乐兼容性
- mysql - 如何将同一张表中的 SUM() 和 COUNT() 表更新到不同的列
- python - Order by 有时在我的查询中不起作用