.net v8 MAUI:如何在上次点击位置显示图像?

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

使用适用于 iOS 的 .net8 MAUI,我在 iOS 应用程序中显示图像。它有一些“热区”,是看不见的按钮。他们会触发某种行动(例如提高分数)。

我想在用户点击的位置显示一种特殊的“鼠标光标”(我将使用 .png )。 我可以使用 AbsoluteLayout、使用 AbsoluteLayout.LayoutBounds 在任何我想要的地方显示光标(png-image)。但是,我无法在 C# 中动态更新此位置。 对此有什么想法吗?

Cursor myCursor = new Cursor("custom.cur"); --> 没有成功,需要 Cursor 类。

.net xaml maui gesture absolutelayout
1个回答
0
投票

我认为你可以简单地使用GestureRecognizers。我已经在 Android 上尝试过,但它应该以同样的方式在 ios 上工作:

xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ImageTap.MainPage"
             Shell.NavBarIsVisible="False">
    <AbsoluteLayout>
        <VerticalStackLayout
            BackgroundColor="Blue" AbsoluteLayout.LayoutBounds="0,0,1000,1000">
            <VerticalStackLayout.GestureRecognizers>
                <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" NumberOfTapsRequired="1" />
            </VerticalStackLayout.GestureRecognizers>
        </VerticalStackLayout>
        <Image x:Name="cursor" Source="cursor.png" AbsoluteLayout.LayoutBounds="0,0,128,128"></Image>
    </AbsoluteLayout>
</ContentPage>

cs:

namespace ImageTap
{
    public partial class MainPage : ContentPage
    {

        public MainPage()
        {
            InitializeComponent();
        }

        private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
        {
            Point? clickedPosition = e.GetPosition((View)sender);
            cursor.TranslationX = clickedPosition.Value.X;
            cursor.TranslationY = clickedPosition.Value.Y;
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.