【问题标题】:Xamarin forms: Top stacklayout is not visible in UI when keyboard is onXamarin 表单:当键盘打开时,顶部堆栈布局在 UI 中不可见
【发布时间】:2018-12-03 12:41:32
【问题描述】:

我的 Xaml:

<StackLayout
   Orientation="Vertical">

   <StackLayout
      Orientation="Horizontal"> 
      //Group labels and back arrow
   </StackLayout>

   <ListView>
      //Message list
   </ListView>

   <Grid>
   //Plus symbol,Editor and send icon
   </Grid>

</StackLayout>

截图:

问题:

在正常屏幕上,顶部有一个栏(红色圆圈)。单击底部顶部栏上的编辑器时,它会隐藏。我需要顶部栏始终在顶部。 此问题仅在 IOS 部分,在 android 中此功能运行正常。我该如何解决这个问题?

【问题讨论】:

  • 您是否将 VerticalOption 设置为 Top StackLayout 的 FillAndExpand?

标签: xamarin.forms stacklayout


【解决方案1】:

UI 向上调整是 iOS 的一项功能。您可以通过自定义渲染器缩小(或保留)视图。

检查this great explanation

还有 this peace of code 用于 iOS 上的键盘自定义渲染器。

【讨论】:

  • 我已经使用另一个自定义渲染器来解决这个问题,感谢您的时间和建议。还在这里更新了正确答案。
【解决方案2】:

就像问题中的图片一样,我的软键盘总是触摸编辑器。所以我为我的编辑器添加了一个自定义渲染器来解决这个问题。 添加自定义渲染器后,顶部栏始终停留在页面顶部。

我使用以下自定义渲染器来解决键盘重叠问题:

using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using HBIClientFacingApp;
using HBIClientFacingApp.iOS;

[assembly:ExportRenderer( typeof(CustomEditor), typeof(CustomEditorRenderer))]
namespace YourNameSpace.iOS
{
    public class CustomEditorRenderer: EditorRenderer
    {
        public ChatEntryRenderer()
        {   
            UIKeyboard.Notifications.ObserveWillShow ((sender, args) => {

            if (Element != null)
            {
                Element.Margin = new Thickness(0,0,0, args.FrameEnd.Height); //push the entry up to keyboard height when keyboard is activated
            }
        });

        UIKeyboard.Notifications.ObserveWillHide ((sender, args) => {

            if (Element != null)
            {
                   Element.Margin = new Thickness(0); //set the margins to zero when keyboard is dismissed
            }

        }); 
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多