GestureRecognizerView.MAUI 1.0.0
dotnet add package GestureRecognizerView.MAUI --version 1.0.0
NuGet\Install-Package GestureRecognizerView.MAUI -Version 1.0.0
此命令旨在在 Visual Studio 的包管理器控制台中使用,因为它使用 NuGet 模块的 Install-Package 版本。
<PackageReference Include="GestureRecognizerView.MAUI" Version="1.0.0" />
对于支持 PackageReference 的项目,将此 XML 节点复制到项目文件中,以引用软件包。
paket add GestureRecognizerView.MAUI --version 1.0.0
NuGet 团队不提供对此客户端的支持。请联系其 维护者 以获取支持。
#r "nuget: GestureRecognizerView.MAUI, 1.0.0"
#r 指令可以在 F# Interactive 和 Polyglot Notebooks 中使用。将此复制到交互式工具或脚本的源代码中,以引用软件包。
// Install GestureRecognizerView.MAUI as a Cake Addin #addin nuget:?package=GestureRecognizerView.MAUI&version=1.0.0 // Install GestureRecognizerView.MAUI as a Cake Tool #tool nuget:?package=GestureRecognizerView.MAUI&version=1.0.0
NuGet 团队不提供对此客户端的支持。请联系其 维护者 以获取支持。
GestureRecognizerView.MAUI
一个用于改进 .net Maui 手势识别器的 View 控件。
GestureRecognizerView
一个捕获指针事件并将它们转换为手势事件的 View 控件。以下是其主要属性和事件:
/// Binding property for use this control in MVVM.
public GestureRecognizerView Self
事件:| | 安卓 | iOS/Mac | Windows | |---|---|---|---| | TapGestureListener | ✅ | ✅ | ✅ | | PanGestureListener | ✅ | ✅ | ✅ | | PinchGestureListener | ✅ | ✅ | ✅ | | PointerGestureListener | ✅ | ✅ | ✅ | | MouseListener | ✅ | | ✅ |
所有事件都具有自己的属性
public class TapGestureEventArgs
{
/// Indicates the gesture recognizer status.
public GestureRecognizerStatus Status
/// Pointer associated to this tap gesture recognizer.
public PointerInfo Pointer
/// X tap coordinate relative to the view.
public double X
/// Y tap coordinate relative to the view.
public double Y
/// Indicates the tap pressure.
public float Pressure
}
public class PanGestureEventArgs
{
/// Indicates the gesture recognizer status.
public GestureRecognizerStatus Status
/// List of pointers associated to this event.
public List<PointerInfo> Pointers
/// Indicates the total change in the x direction since the beginning of the gesture.
public double TotalX
/// Indicates the total change in the y direction since the beginning of the gesture.
public double TotalY
/// Indicates the increment/decrement change in the x direction since the last update of the gesture.
public double IncX
/// Indicates the increment/decrement change in the y direction since the last update of the gesture.
public double IncY
}
public class PinchGestureEventArgs
{
/// Indicates the gesture recognizer status.
public GestureRecognizerStatus Status
/// List of pointers associated to this event.
public List<PointerInfo> Pointers
/// Indicates the total change in the scale since the beginning of the gesture.
public double Scale
/// Indicates the increment/decrement of the scale since the last update of the gesture.
public double ScaleIncrement
/// Indicates the total change in the vector roation between the 2 touch points since the beginning of the gesture.
public double Rotation
/// Indicates the increment/decrement of the vector rotation between the 2 touch points since the last update of the gesture.
public double RotationIncrement
}
public class PointerGestureEventArgs
{
/// Indicates the gesture recognizer status.
public PointerRecognizerStatus Status
/// Pointer associated to this event.
public PointerInfo Pointer
/// X pointer coordinate relative to the view.
public double X
/// Y pointer coordinate relative to the view.
public double Y
/// Indicates if pointer is pressed.
public bool Pressed
/// Indicates the pointer pressure.
public float Pressure
}
public class MouseEventArgs
{
/// Indicates the mouse status.
public MouseRecognizerStatus Status
/// Pointer associated to this event.
public PointerInfo Pointer
/// X pointer coordinate relative to the view.
public double X
/// Y pointer coordinate relative to the view.
public double Y
/// Indicates the wheel movement direction (negative/positive).
public double MouseWheelDelta
/// Indicates if horizontal wheel has moved.
public bool IsHorizontalMouseWheel
/// Indicates if right button is pressed.
public bool IsRightButtonPressed
/// Indicates if left button is pressed.
public bool IsLeftButtonPressed
/// Indicates if middle button is pressed.
public bool IsMiddleButtonPressed
}
安装和配置 GestureRecognizerView
下载并安装您应用的 GestureRecognizerView.MAUI NuGet 软件包。
在您的
MauiProgram.cs
中初始化插件// Add the using to the top using GestureRecognizerView.MAUI; public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() .UseGestureRecognizerView(); // Add the use of the plugging return builder.Build(); }
使用 GestureRecognizerView
在 XAML 中,确保添加正确的 XML 命名空间
xmlns:grv="clr-namespace:GestureRecognizerView.MAUI;assembly=GestureRecognizerView.MAUI"
使用控件
<Grid>
<VerticalStackLayout VerticalOptions="Center">
<Border WidthRequest="300" HeightRequest="300">
<Grid>
<Image x:Name="img" HorizontalOptions="Fill" VerticalOptions="Fill" Aspect="AspectFit" Source="dotnet_bot.png" />
<grv:GestureRecognizerView x:Name="recognizerView" BindingContext="{x:Reference mainPage}" HorizontalOptions="Fill" VerticalOptions="Fill" Self="{Binding GestureRecognizer}" />
</Grid>
</Border>
</VerticalStackLayout>
</Grid>
配置事件
private GestureRecognizerView gestureRecognizer;
public GestureRecognizerView GestureRecognizer
{
get => gestureRecognizer;
set
{
gestureRecognizer = value;
if (gestureRecognizer != null)
{
gestureRecognizer.TapGestureListener += RecognizerView_TapGestureListener;
gestureRecognizer.PointerGestureListener += RecognizerView_PointerGestureListener;
gestureRecognizer.PanGestureListener += RecognizerView_PanGestureListener;
gestureRecognizer.PinchGestureListener += RecognizerView_PinchGestureListener;
gestureRecognizer.MouseListener += RecognizerView_MouseListener;
}
}
}
使用事件
private void RecognizerView_MouseListener(object sender, MouseEventArgs args)
{
if (args.Status == MouseRecognizerStatus.WheelMoved)
{
if (args.MouseWheelDelta < 0)
img.Scale -= 0.05;
else if (args.MouseWheelDelta > 0)
img.Scale += 0.05;
}
Debug.WriteLine($"Mouse status={args.Status} X={args.X} Y={args.Y} WheelDelta={args.MouseWheelDelta} LeftPressed={args.IsLeftButtonPressed} RightPressed={args.IsRightButtonPressed}");
}
private void RecognizerView_PinchGestureListener(object sender, PinchGestureEventArgs args)
{
switch (args.Status)
{
case GestureRecognizerStatus.Started:
initScale = img.Scale;
initRotation = img.Rotation;
break;
case GestureRecognizerStatus.Running:
img.Scale += args.ScaleIncrement;
img.Rotation += args.RotationIncrement;
break;
case GestureRecognizerStatus.Complete:
img.Scale += args.ScaleIncrement;
img.Rotation += args.RotationIncrement;
break;
case GestureRecognizerStatus.Cancel:
img.Scale = initScale;
img.Rotation = initRotation;
break;
}
}
private void RecognizerView_PanGestureListener(object sender, PanGestureEventArgs args)
{
switch(args.Status)
{
case GestureRecognizerStatus.Started:
initX = img.TranslationX;
initY = img.TranslationY;
break;
case GestureRecognizerStatus.Running:
img.TranslationX = initX + args.TotalX;
img.TranslationY = initY + args.TotalY;
break;
case GestureRecognizerStatus.Complete:
img.TranslationX = initX + args.TotalX;
img.TranslationY = initY + args.TotalY;
initX = img.TranslationX;
initY = img.TranslationY;
break;
case GestureRecognizerStatus.Cancel:
img.TranslationX = initX;
img.TranslationY = initY;
break;
}
}
private void RecognizerView_PointerGestureListener(object sender, PointerGestureEventArgs args)
{
if (args.Status != PointerRecognizerStatus.Move)
Debug.WriteLine($"Pointer status={args.Status} X={args.X} Y={args.Y} Pressed={args.Pressed}");
}
private void RecognizerView_TapGestureListener(object sender, TapGestureEventArgs args)
{
if (args.Status == GestureRecognizerStatus.Complete)
{
if ((DateTime.Now - lastTap).TotalMilliseconds <= 500)
{
img.TranslationX = img.TranslationY = 0;
img.Scale = 1;
img.Rotation = 0;
}
lastTap = DateTime.Now;
}
}
所有事件都有一个包含所有关联指针的 Pointer(s) 属性:PointerInfo 有以下属性
/// Unique ID for this pointer.
public uint PointerId
/// Start position when the pointer is detected in the View.
public Point StartPoint
/// Pointer position in the previews event.
public Point PreviewsPoint
/// Last position of the pointer over the View.
public Point EndPoint
/// Start time when the pointer is detected in the View.
public DateTime StartTime
/// Previews pointer event time.
public DateTime PreviewsTime
/// Last time when the pointer has raised an event in the view.
public DateTime EndTime
/// Indicates if the pointer is pressed.
public bool Pressed
/// Start pressure when the pointer is detected in the View.
public float StartPressure
/// Pointer pressure in the previews event.
public float PreviewsPressure
/// Last pressure of the pointer over the View.
public float EndPressure
/// Pointer device type.
public PointerType PointerType
/// For pointer of mouse devices indicates the wheel movement direction (negative/positive).
public double MouseWheelDelta
/// For pointer of mouse devices indicates if horizontal wheel has moved.
public bool IsHorizontalMouseWheel
/// For pointer of mouse devices indicates if right button is pressed.
public bool IsRightButtonPressed
/// For pointer of mouse devices indicates if left button is pressed.
public bool IsLeftButtonPressed
/// For pointer of mouse devices indicates if middle button is pressed.
public bool IsMiddleButtonPressed
产品 | 版本 兼容的和额外的计算目标框架版本。 |
---|---|
.NET | net7.0 兼容。 net7.0-android 已计算。 net7.0-android33.0 兼容。 net7.0-ios 已计算。 net7.0-ios16.1 兼容。 net7.0-maccatalyst 已计算。 net7.0-maccatalyst16.1 兼容。 net7.0-macos 已计算。 net7.0-tvos 已计算。 net7.0-windows 已计算。 net7.0-windows10.0.19041 兼容。 net8.0 已计算。 net8.0-android 已计算。 net8.0-browser 已计算。 net8.0-ios 已计算。 net8.0-maccatalyst 已计算。 net8.0-macos 已计算。 net8.0-tvos 已计算。 net8.0-windows 已计算。 |
-
net7.0
- 无依赖项。
-
net7.0-android33.0
- 无依赖项。
-
net7.0-ios16.1
- 无依赖项。
-
net7.0-maccatalyst16.1
- 无依赖项。
-
net7.0-windows10.0.19041
- 无依赖项。
NuGet 包 (1)
显示依赖于GestureRecognizerView.MAUI的NuGet包的前1个
包 | 下载 |
---|---|
PaintView.MAUI
一种多平台控件,可以使用查找器、鼠标或指针进行绘画。视图具有用作清晰的绘图区域或使用其控制按钮的属性 |
GitHub 仓库
此包未由任何流行的GitHub仓库使用。
版本 | 下载 | 最后更新 |
---|---|---|
1.0.0 | 625 | 4/25/2023 |