C# xamarin.forms-页面底部的滑动信息框

C# xamarin.forms-页面底部的滑动信息框,c#,animation,xamarin,mvvm,xamarin.forms,C#,Animation,Xamarin,Mvvm,Xamarin.forms,我正在学习xamarin.forms技术。标题的意思是我想制作滑动信息框(从屏幕的底部、左侧或右侧)。所有内容都应位于页面/视图的底部。同样,在xamarin.forms的底部放置一些东西也很棘手 我想这样做而不是对话框,因为我不想在警报对话框弹出时感觉ui,也不想强迫用户单击任何东西 你们能告诉我怎么做吗?你们应该使用AbsoluteLayout,这里有一个例子: // ContentPage: var layout = new StackLayout { // you page con

我正在学习xamarin.forms技术。标题的意思是我想制作滑动信息框(从屏幕的底部、左侧或右侧)。所有内容都应位于页面/视图的底部。同样,在xamarin.forms的底部放置一些东西也很棘手

我想这样做而不是对话框,因为我不想在警报对话框弹出时感觉ui,也不想强迫用户单击任何东西


你们能告诉我怎么做吗?

你们应该使用AbsoluteLayout,这里有一个例子:

// ContentPage:

var layout = new StackLayout {
 // you page content
};

Content = new NotifyLayoutView(layout);
和视图类:

public class NotifyLayoutView : AbsoluteLayout
{
   public NotifyLayoutView(View content)
   {
        var flash = new StackLayout
        {
            BackgroundColor = Color.Red,
            HorizontalOptions = LayoutOptions.FillAndExpand,
            Children = {
               new Label { Text = "My notification" }
            }
        };

        SetLayoutFlags(content, AbsoluteLayoutFlags.All);
        SetLayoutBounds(content, new Rectangle(0f, 0f, 1f, 1f));
        SetLayoutFlags(flash, AbsoluteLayoutFlags.WidthProportional | 
        AbsoluteLayoutFlags.PositionProportional);
        SetLayoutBounds(flash, new Rectangle(0.5, 0.99, 0.95, AutoSize));
        Children.Add(content);
        Children.Add(flash);
   }
}
要更改flash可见性,可以使用:

// open
await flash.ScaleTo(1.0f, 100);
await flash.FadeTo(1.0f, 100);

// hide
await layout.ScaleTo(0.0f);
await layout.FadeTo(0.0f);

或者尝试使用(nuget软件包:)

而不是使用任何nuget软件包。你可以自己创造它,这样你就可以控制它。 使用PanGesture和TranslateTo方法以及带有约束的相对布局来创建它

void PanGestureRecognizer_PanUpdated(System.Object sender, Xamarin.Forms.PanUpdatedEventArgs e)
{
y = e.TotalY;
switch (e.StatusType)
{
case GestureStatus.Started:
break;
case GestureStatus.Canceled:
break;
case GestureStatus.Running:
if ((y >= 5 || y <= -5) && !IsTurnY)
{
IsTurnY = true;
}
if (IsTurnY)
{
if (y <= valueY)
{
//iOS devices has top and bottom insets so the value is changed accordingly.
//get the top and bottom insets and adjst the values accordingly for bottom sheet to work correct in real devices
double valueToDeduct = 180;
//upwards dragged
if ((currentY + (-1 * y)) < (App.screenHeight — valueToDeduct))
{
BottomSheet.TranslateTo(BottomSheet.X, -(currentY + (-1 * y)));
currentY = currentY — y;
//Task.Delay(200);
}
else
{
//to avoid the bottomsheet go beyond the device height
BottomSheet.TranslateTo(BottomSheet.X, -(App.screenHeight — valueToDeduct));
currentY = (App.screenHeight — valueToDeduct);
}
}
if (y >= valueY)
{
//downwards dragged
if ((currentY — y) > 0)
{
BottomSheet.TranslateTo(BottomSheet.X, -(currentY — y));
currentY = currentY — y;
//Task.Delay(200);
}
else
{
//to avoid bottomsheet to hide below the screen height
BottomSheet.TranslateTo(BottomSheet.X, -0);
currentY = 0;
}
}
}
}
break;
case GestureStatus.Completed:
//store the translation applied during the pan
valueY = y;
IsTurnY = false;
break;
}
}
void pangesture识别器\u PanUpdated(System.Object sender,Xamarin.Forms.PanUpdatedEventArgs e)
{
y=e.TotalY;
开关(如状态类型)
{
案例手势状态。已启动:
打破
案例手势状态。已取消:
打破
案例手势状态。正在运行:
如果((y>=5 | | y 0)
{
底部薄板.平移到(底部薄板.X,-(当前y-y));
电流y=电流y-y;
//任务延迟(200);
}
其他的
{
//避免底部板材隐藏在屏幕高度下方
底页.平移到(底页.X,-0);
电流y=0;
}
}
}
}
打破
案例管理状态。已完成:
//存储平移期间应用的平移
valueY=y;
IsTurnY=false;
打破
}
}
这是你可以参考的资源


你的目标平台是什么?你的目标是显示什么样的信息?伙计,如果你不需要真正的对话,只想显示信息而不进行交互,那么为什么不使用toasts呢?尼克,你说得对。我最终使用了toasts;)你能解释一下
1.0f
的意思吗大小