我的页面看起来像这样:
如果用户关注其中一个条目,则页面被“锁定” . 用户不能按照以下方式上下移动:
我使用ContentPage和ScrollView作为主要布局 . 我也尝试在各种模式下设置Window.SetSoftInputMode(),但一切都保持不变 .
有没有任何模块化的方法来解决这个问题(我有一个StackLayout上面的条目与HeightRequest = 0的条目,当其中一个条目集中时,我将HeightRequest更改为键盘的高度)?
Update 我按照以下方式实现了这个:
添加了新的自定义控件CustomEntry,基本上是Entry:
<?xml version="1.0" encoding="UTF-8"?>
<Entry xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Framework.Controls.CustomEntry"
TextColor="{StaticResource MainPurple}"
PlaceholderColor="{StaticResource MainPurpleLight}"
HeightRequest="45"
FontSize="14"
Focused="CustomEntryFocused"
Unfocused="CustomEntryUnfocused">
</Entry>
private void CustomEntryFocused(object sender, FocusEventArgs e)
{
var stackParent = StackParent as StackLayout;
stackParent?.Children.Add(new StackLayout() { HeightRequest = `KeyboardHeight });`
}
private void CustomEntryUnfocused(object sender, FocusEventArgs e)
{
var stackParent = StackParent as StackLayout;
stackParent?.Children.RemoveAt(stackParent.Children.Count - 1);
}
2 回答
仅在您的iOS项目中使用Xam.Plugins.Forms.KeyboardOverlap插件(不是PCL,而不是Android),以及iOS项目调用:
你打电话之后必须这样做
Xamarin.Forms.Init().
这是一个例子:https://github.com/paulpatarinski/Xamarin.Forms.Plugins/tree/master/KeyboardOverlap/SampleApp
您也可以使用以下代码手动滚动页面
您需要将网格或stacklayout放在滚动视图中并将焦点事件放在条目上 .