У меня есть решение, используемое в моем проекте, вы можете проверить это, чтобы быть полезным для вас.
Использование Focused/UnFocused
метода Entry
в формах Xamarin, чтобы узнать, показывает ли клавиатура. Затем вы можете детализировать представление Entry для перехода к описанному выше разделу «Клавиатура», используя анимацию TranslateTo для ее реализации.
Вот 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>
Focused/UnFocused
в ContentPage следующим образом:
private void myEntry_Focused(object sender, FocusEventArgs e)
{
// Decete whethe in iOS platform
if(Device.RuntimePlatform == Device.iOS)
{
// 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)
{
// Decete whethe in iOS platform
if (Device.RuntimePlatform == Device.iOS)
{
Console.WriteLine("unFocused");
myEntry.TranslateTo(0, 0, 50);
}
}
Тогда вы увидите эффект следующим образом: