我面临的问题是,屏幕底部有条目,当键盘弹出时,它会在用户键入值时完全隐藏该条目,并且仅在iOS上发生。我尝试使用scrollview,但仍然无法正常工作。
<ContentView.Content>
<AbsoluteLayout Margin="0,0,30,0">
<Entry
x:Name="searchBar"
AbsoluteLayout.LayoutBounds="0,0,1,AutoSize"
AbsoluteLayout.LayoutFlags="WidthProportional"
BackgroundColor="White"
HeightRequest="40"
Placeholder="Enter sensor"
TextChanged="SearchBar_OnTextChanged"
TextColor="{DynamicResource RelogixDarkGray}"
VerticalOptions="Center" />
<ListView
x:Name="dataListView"
AbsoluteLayout.LayoutBounds="5,40,.98,.4"
AbsoluteLayout.LayoutFlags="SizeProportional"
BackgroundColor="White"
CachingStrategy="RecycleElement"
HasUnevenRows="True"
IsVisible="False"
ItemTapped="ListView_OnItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Margin="5" Padding="0">
<Label
BackgroundColor="White"
FontFamily="{StaticResource NormalFont}"
FontSize="16"
Text="{Binding .}"
TextColor="#FF464859"
VerticalOptions="Center"
VerticalTextAlignment="Center" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</AbsoluteLayout>
我在我的项目中使用了一个解决方案,您可以检查一下是否对您有帮助。
在Xamarin Forms中使用Focused/UnFocused
的Entry
方法,以了解键盘是否显示。然后,您可以使用TranslateTo动画实现它,从而详细了解Entry的视图以移至Keyboard的上方。
这里是Xaml代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="AppkeyboardHideEntryInIOS.MainPage">
<StackLayout x:Name="MainLayout" Padding="20">
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Entry x:Name="myEntry" Placeholder="Entry" Focused="myEntry_Focused" Unfocused="myEntry_Unfocused"/>
</StackLayout>
</ContentPage>
[ContentPage中的Focused/UnFocused
如下:
private void myEntry_Focused(object sender, FocusEventArgs e)
{
// belong to iPhone X seriors device , the height of keyboard is 333
if (Height > 800)
{
// check whether entry need to tarnslate
if (Height - myEntry.Y - myEntry.Height < 333)
{
myEntry.TranslateTo(0, -333, 50);
}
}else
{
// belong to iPhone 6,7,8 seriors device, the height of keyboard is 258
// check whether entry need to tarnslate
if (Height - myEntry.Y - myEntry.Height < 258)
{
myEntry.TranslateTo(0, -258, 50);
}
}
}
private void myEntry_Unfocused(object sender, FocusEventArgs e)
{
Console.WriteLine("unFocused");
myEntry.TranslateTo(0, 0, 50);
}
然后您将看到如下效果: