Xamarin.Forms如何使用自定义渲染器创建底表?

问题描述 投票:1回答:1

我尝试调用一些nuget程序包,但无济于事!我的视图也有一个地图,想让底部的页面具有一些与地图交互的选项!

xamarin xamarin.ios xamarin.forms xamarin.android
1个回答
0
投票

您可以在Xamarin表单中使用Pan Gesture来创建底部工作表。要通过滑动来移动底部工作表,可以使用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;
}
}

这里是值得研究的好资源https://medium.com/xamarinlife/bottomsheet-in-xamarin-forms-f99fd8b48bc4

© www.soinside.com 2019 - 2024. All rights reserved.