Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 可访问性元素在通过刷卡器导航时不受关注,但它';在触摸元素的同时聚焦_Ios_Xamarin_Xamarin.forms_Xamarin.ios_Accessibility - Fatal编程技术网

Ios 可访问性元素在通过刷卡器导航时不受关注,但它';在触摸元素的同时聚焦

Ios 可访问性元素在通过刷卡器导航时不受关注,但它';在触摸元素的同时聚焦,ios,xamarin,xamarin.forms,xamarin.ios,accessibility,Ios,Xamarin,Xamarin.forms,Xamarin.ios,Accessibility,我已经创建了一个自定义控件,用于在应用程序中创建导航窗格,该应用程序具有一个内容区域和一个滑动面板,使用UIView从Xamarin.iOS中的页面边缘滑出,我需要为其提供可访问性支持。首先,我创建了一个视图,在其中我将在内容区域中添加元素,并将其转换为iOS渲染器中的本机视图。然后,我尝试通过刷子导航内容视图中添加的元素,但它没有移动,但在触摸元素时聚焦。我已将isAccessibilityElement设置为false,以使内容视图可聚焦。我需要使元素在刷卡时可以访问。有人能帮忙吗?先谢谢你

我已经创建了一个自定义控件,用于在应用程序中创建导航窗格,该应用程序具有一个内容区域和一个滑动面板,使用UIView从Xamarin.iOS中的页面边缘滑出,我需要为其提供可访问性支持。首先,我创建了一个视图,在其中我将在内容区域中添加元素,并将其转换为iOS渲染器中的本机视图。然后,我尝试通过刷子导航内容视图中添加的元素,但它没有移动,但在触摸元素时聚焦。我已将isAccessibilityElement设置为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.表格

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);
    }
}
公共类CustomControlRenderer:ViewRenderer
{
公共CustomControlRenderer()
{
}
土生土长的拉威尔;
客户控制抽屉;
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
碱基。一个元素改变(e);
if(例如NewElement!=null){
抽屉=e.新元素;
如果(nativeDrawer==null)
{
nativeDrawer=new Native();
UIView v=新UIView();
v、 帧=新的CGRect(0,0,600,1500);
nativeDrawer.ContentView=CustomControlRenderer.ConvertFormsToActiveView(drawer.ContentView、v.Frame、drawer、drawer.BindingContext);
}
设置NATIVECONTROL(nativeDrawer);
}
}
内部静态UIView ConvertFormsToActiveView(Xamarin.Forms.View视图、CGRect大小、CustomControl抽屉、对象绑定上下文)
{
如果(视图==null)
返回null;
if(view.BindingContext==null)
{
if(bindingContext!=null)
{
view.BindingContext=BindingContext;
}
其他的
{
view.BindingContext=drawer.BindingContext;
}
}
返回GetNativeView(视图、抽屉、视图.BindingContext、0、0、size.Width、size.Height);
}
}

这是一个预期结果。如果要滚动控件(如UItableView)或导航到另一页,我们需要在可访问性模式下用三个手指滑动屏幕。@LucasZhang MSFT感谢您的回复。我无法通过刷卡移动到下一个元素。您能否共享您的示例,以便我可以在我这边测试它。您的代码中似乎没有问题。这是预期的结果。如果要滚动控件(如UItableView)或导航到另一页,我们需要在可访问性模式下用三个手指滑动屏幕。@LucasZhang MSFT感谢您的回复。我无法通过刷卡移动到下一个元素。您能否共享您的示例,以便我可以在我这边进行测试。您的代码中似乎没有问题。