Xamarin表单键盘重叠输入字段 [英] Xamarin form Keyboard overlapping Entry field
本文介绍了Xamarin表单键盘重叠输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在打开键盘时滚动页面.现在,键盘覆盖了我的其他输入字段. 我尝试了软输入法.但是它不能以xamarin形式工作.
I want to scroll the page when the keyboard is opened. Right now the keyboard is covering my other entry fields. I have tried the soft input method. But it's not working in xamarin form.
我该怎么办?
推荐答案
您必须在输入焦点上手动添加翻译.尝试在构造函数中使用以下代码:
you have to add manually translation on entry focus. Try below code in constructor:
this.entryname.Focused += (s, e) => { SetLayoutPosition(onFocus: true); };
this.entryname.Unfocused += (s, e) => { SetLayoutPosition(onFocus: false); };
然后在粘贴以下方法之后:
Then after just paste below method :
void SetLayoutPosition(bool onFocus)
{
if (onFocus)
{
if (Device.RuntimePlatform == Device.iOS)
{
this.CenteredStackLayout.TranslateTo(0, -100, 50);
}
else if (Device.RuntimePlatform == Device.Android)
{
this.CenteredStackLayout.TranslateTo(0, -100, 50);
}
}
else
{
if (Device.RuntimePlatform == Device.iOS)
{
this.CenteredStackLayout.TranslateTo(0, 0, 50);
}
else if (Device.RuntimePlatform == Device.Android)
{
this.CenteredStackLayout.TranslateTo(0, 0, 50);
}
}
}
您可以根据需要将"50"更改为任意值.
You can change "50" to any value according to your requirement.
这篇关于Xamarin表单键盘重叠输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文