0

我想在启动应用程序后创建一个教程页面,让用户了解应用程序中的功能以及如何使用它。

例如anydesk应用程序中的教程页面↓

在此处输入图像描述

那么,如何使用 XF 创建这个页面呢?

我应该使用什么术语或关键字在 google 上查找有关此的示例,例如“入职页面”?

更新

试图在android上添加这个功能,它工作正常

现在的问题是如何在 Ios 上做到这一点?

4

2 回答 2

0

您可以通过简单的方法实现此效果。
使用 2 个布局,第一个是原始视图,另一个
嵌套在第一个布局内(Opacity< 1)是教程页面。

.XAML:

    <ContentPage.Content>

      
        <!--THIS IS THE LAYOUT FROM BEHIND-->
        <AbsoluteLayout x:Name="mainLayout">
          
            <!--Controls...-->

          
            <!--THIS CAN BE THE TUTORIAL PAGE, SEE THE OPACITY-->
            <AbsoluteLayout x:Name="tutorialLayout" IsVisible="true" 
            AbsoluteLayout.LayoutBounds="0, 0, [total width], [total height]" Opacity="0.8">
                        <!--Controls...-->
            </AbsoluteLayout>

        </AbsoluteLayout>


    </ContentPage.Content>  
于 2020-07-14T12:47:22.570 回答
0

在阅读了很多资源之后,我最终使用了自定义渲染器

在共享项目中

1-创建一个 Xamarin.Forms 自定义控件。

public class FeatureDiscoveryTarget : View
{
    public Element Target { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
}

public class FeatureDiscoverySequence : View
{
    public IList<FeatureDiscoveryTarget> Targets { get; }
    public Action ShowAction { get; set; }
    public FeatureDiscoverySequence()
    {
        Targets = new List<FeatureDiscoveryTarget>();
    }
    public void ShowFeatures()
    {
        ShowAction?.Invoke();
    }
}

2-使用Xamarin.Forms中的自定义控件。

.XAML

<StackLayout Orientation="Vertical" Padding="3">
  
    <Button x:Name="BtnTest" Text="Test Feature Discovery" Clicked="Button_Clicked"/>

    <Button x:Name="Btn1" Text="Feature 1"  HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
    
    <StackLayout Orientation="Horizontal" >
        <Button x:Name="Btn2" Text="Feature 2"  />
        <Button x:Name="Btn3" Text="Feature 3" HorizontalOptions="EndAndExpand"  />
    </StackLayout>
   
    <Button x:Name="Btn4" Text="Feature 4" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"  />

    <local:FeatureDiscoverySequence x:Name="TapTargetSequence">
        <local:FeatureDiscoverySequence.Targets>
            <local:FeatureDiscoveryTarget Target="{x:Reference Name=Btn1}" Title="Feature 1" Description="Details.... " />
            <local:FeatureDiscoveryTarget Target="{x:Reference Name=Btn2}" Title="Feature 2" Description="Details.... " />
            <local:FeatureDiscoveryTarget Target="{x:Reference Name=Btn3}" Title="Feature 3" Description="Details.... " />
            <local:FeatureDiscoveryTarget Target="{x:Reference Name=Btn4}" Title="Feature 4" Description="Details.... " />
        </local:FeatureDiscoverySequence.Targets>
    </local:FeatureDiscoverySequence>

</StackLayout>

。CS

private void Button_Clicked(object sender, EventArgs e)
    {
        TapTargetSequence.ShowFeatures();
    }

在安卓项目中

1-仅将此添加到 android 项目

2- 创建 MainActivity 类的新实例

public static MainActivity Instance { get; private set; }

protected override void OnCreate(Bundle savedInstanceState)
 {
     // ... 
     LoadApplication(new App());
     Instance = this;
 }

3-为控件创建自定义渲染器。

using System;
using Xamarin.Forms;
using Android.Views;
using Android.Widget;
using Android.Content;
using View = Android.Views.View;
using System.Collections.Generic;
using Com.Getkeepsafe.Taptargetview;
using Xamarin.Forms.Platform.Android;
using Color = Android.Resource.Color;

[assembly: ExportRenderer(typeof(FeatureDiscoverySequence), typeof(SequenceRenderer))]

namespace YourNameSpace.Droid
{
    class SequenceRenderer : Xamarin.Forms.Platform.Android.AppCompat.ViewRenderer<FeatureDiscoverySequence, View>
    {
        public SequenceRenderer(Context context) : base(context) { }
        protected override void OnElementChanged(ElementChangedEventArgs<FeatureDiscoverySequence> e)
        {
            base.OnElementChanged(e);
            e.NewElement.ShowAction = new Action(ShowFeatures);
        }
        private void ShowFeatures()
        {
            var targets = new List<Com.Getkeepsafe.Taptargetview.TapTarget>();
            foreach (var target in Element.Targets)
            {
                var formsView = target.Target;
                string title = target.Title;
                string description = target.Description;

                var renderer = Platform.GetRenderer((Xamarin.Forms.View) formsView);

                var property = renderer?.GetType().GetProperty("Control");

                var targetView = (property != null) ? (View) property.GetValue(renderer) : renderer?.View;

                if (targetView != null)
                {
                    targets.Add
                    (
                        TapTarget
                            .ForView(targetView, title, description)
                            .DescriptionTextColor(Color.White)
                            .DimColor(Color.HoloBlueLight)
                            .TitleTextColor(Color.Black)
                            .TransparentTarget(true)
                            .TargetRadius(75)
                    );
                }
            }
            new TapTargetSequence(MainActivity.Instance).Targets(targets).Start();
        }
    }
}

在 iOS 项目中 ...Todo

安卓上的结果

了解更多信息

  1. 安卓版
  2. IOS
  3. KeepSafe/TapTargetView Github
  4. Xamarin.Forms 自定义渲染器
于 2020-07-15T12:00:34.107 回答