I将类似的pinchgesturerangognizer添加到了毛伊岛编辑XAML中。捏合起作用,但编辑器不再收到TAP事件,基本上已经死了。我已经明确添加了TAP识别器,但是编辑器的大多数高级功能(事件)仍然死了,例如将光标放入文本中的用户taps。
<Editor.GestureRecognizers>
<PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />
</Editor.GestureRecognizers>
eDit:我通过在三星Galaxy S24,Android14上进行USB-Cable调试问题
using Android.Views;
using AndroidX.AppCompat.Widget;
using Microsoft.Maui.Handlers;
namespace MauiApp2.Platforms.Android
{
public class CustomEditorHandler : EditorHandler
{
protected override void ConnectHandler(AppCompatEditText nativeView)
{
base.ConnectHandler(nativeView);
//add touch event
nativeView.Touch += NativeView_Touch; ;
}
protected override void DisconnectHandler(AppCompatEditText nativeView)
{
base.DisconnectHandler(nativeView);
nativeView.Touch -= NativeView_Touch; ;
}
private void NativeView_Touch(object? sender, global::Android.Views.View.TouchEventArgs e)
{
if (sender is AppCompatEditText nativeView)
{
// check the click event
if (e.Event.Action == MotionEventActions.Down)
{
// request focus
nativeView.RequestFocus();
}
// transfer the click event
if (e.Event.PointerCount > 1)
{
// if Pinch guesture,prevent this operation
e.Handled = false;
}
else
{
// if click, do it
e.Handled = true;
}
}
}
}
}
,然后我创建了一个扩展编辑器的类。
public class CustomEditor : Editor
{
}
最终,我在
MauiProgram.cs
.中注册此自定义编辑器
.ConfigureMauiHandlers(handlers =>
{
#if ANDROID
handlers.AddHandler(typeof(CustomEditor), typeof(MauiApp2.Platforms.Android.CustomEditorHandler));
#endif
}); ;
<local:CustomEditor>
<local:CustomEditor.GestureRecognizers>
<PinchGestureRecognizer PinchUpdated="PinchGestureRecognizer_PinchUpdated" />
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped">
</TapGestureRecognizer>
</local:CustomEditor.GestureRecognizers>
</local:CustomEditor>