开发者社区> 问答> 正文

可访问性元素在通过滑动器导航时没有聚焦,而是在触摸元素时聚焦。

我已经创建了一个自定义控件,用于在应用程序中创建导航窗格,该控件有一个内容区域和一个滑动面板,该面板可以从Xamarin.IOS中的页面边缘滑出,使用UIView,我需要为其提供可访问性支持。首先,我创建了一个视图,在其中我将添加内容区域中的元素,并将其转换为IOS呈现器中的本机视图。然后,我尝试导航添加到内容视图通过滑动器显示,但不是移动,而是在触摸元素时聚焦。...我已经准备好了isAccessibilityElement to false使内容视图具有可聚焦性...我需要在滑动的时候让这些元素可以访问。有人能帮忙吗?提前谢谢。请查找以下代码:

简单的示例代码片段:

<drawer:CustomControl  x:Name="drawer">
    <drawer:CustomControl.ContentView>
        <StackLayout Margin="0,100,0,0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
            <Button Text="Button" />
            <Label Text="ContentView"/>
            <Button  Text=" Button2"/>
            <Label Text="ContentView2"/>
        </StackLayout>
    </drawer:CustomControl.ContentView>
</drawer:CustomControl>

本机代码段:

public class SimpleControl : UIView
{
    UIView contentView;
    public UIView ContentView
    {
        get
        {
            return this.contentView;
        }

        set
        {
            this.contentView = value;
            this.Add(this.contentView);
        }
    }

    public override void LayoutSubviews()
    {
        base.LayoutSubviews();

        this.IsAccessibilityElement = false;
    }
}
Xamarin.Forms

public class CustomControl: View
{
    public View ContentView
    {
        get { return (View)GetValue(ContentViewProperty); }
        set { SetValue(ContentViewProperty, value); }
    }

    public static readonly BindableProperty ContentViewProperty =  BindableProperty.Create(nameof(ContentView), typeof(View), typeof(CustomControl), null, BindingMode.Default);


    public CustomControl()
    {
    }

    protected override SizeRequest OnSizeRequest(double widthConstraint, double heightConstraint)
    {
        if (Double.IsNaN(widthConstraint) || Double.IsNaN(heightConstraint)
            || Double.IsInfinity(widthConstraint) || Double.IsInfinity(heightConstraint))
        {
            SizeRequest size = base.OnMeasure(widthConstraint, heightConstraint);
            widthConstraint = size.Request.Width;
            heightConstraint = size.Request.Height;

        }
        return new SizeRequest(new Size(widthConstraint, heightConstraint));
    }
}

IOS渲染器:

public class CustomControlRenderer : ViewRenderer<CustomControl, Native>
{
    public CustomControlRenderer()
    {
    }

     Native nativeDrawer;
     CustomControl drawer;
     protected override void OnElementChanged(ElementChangedEventArgs<CustomControl> e)
     {
        base.OnElementChanged (e);
        if (e.NewElement != null) {
            drawer = e.NewElement;

            if (nativeDrawer == null)
            {
                nativeDrawer = new Native ();
                UIView v = new UIView();
                v.Frame = new CGRect(0, 0, 600, 1500);
                nativeDrawer.ContentView = CustomControlRenderer.ConvertFormsToNativeView(drawer.ContentView, v.Frame, drawer, drawer.BindingContext);
            }

            SetNativeControl(nativeDrawer);
        }
     }


    internal static UIView ConvertFormsToNativeView(Xamarin.Forms.View view, CGRect size, CustomControl drawer, object bindingContext)
    {
        if (view == null)
            return null;
        if (view.BindingContext == null)
        {
            if (bindingContext != null)
            {
                view.BindingContext = bindingContext;
            }
            else
            {
                view.BindingContext = drawer.BindingContext;
            }
        }

        return GetNativeView(view, drawer, view.BindingContext, 0, 0, size.Width, size.Height);
    }
}

展开
收起
游客5akardh5cojhg 2019-12-16 22:23:51 441 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
AMAP INSIDE 智能定位带来的时代新机会——互联网世界底图 立即下载
3D动画的菜谱式灯光与云渲染 立即下载
触摸时空的力量 立即下载