我已经创建了一个自定义控件,用于在应用程序中创建导航窗格,该控件有一个内容区域和一个滑动面板,该面板可以从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);
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。