On Xamarin Forms page (code below) when user taps on Entry (text field) on Android, the screen moves up and keyboard appears which is fine. However, on iOS keyboard covers the Entry. In native development it needs to be handled in code but how can this problem be resolved in Xamarin Forms? I think only solution is to try regular Xamarin and develop separate platform code there.
Wrap your Entry
elements in a ScrollView
For that you can use below code in constructor:
public YourPage()
{
InitializeComponent();
this.yourEntry.Focused += (s, e) => { SetLayoutPosition(onFocus: true); };
this.yourEntry.Unfocused += (s, e) => { SetLayoutPosition(onFocus: false); };
}
Implement method like:
void SetLayoutPosition(bool onFocus)
{
if (onFocus)
{
if (Device.RuntimePlatform == Device.iOS)
{
this.CenterStackLayout.TranslateTo(0, -100, 50);
}
}
else
{
if (Device.RuntimePlatform == Device.iOS)
{
this.CenterStackLayout.TranslateTo(0, 0, 50);
}
}
}
Don't Forgot to add your Root Layout into ScrollView, as @Jason has mentioned.
In my case, I'm using grid and stacks, wrap my root layout in a ScrollView, and set the orientation to neither. And it works without any Nuget and code-behind. Actually, I tried the IQKeyboardManager, but none of it works, dependency deprecation. Thanks to @Jason for the idea.
Referring to https://forums.xamarin.com/discussion/151812/ios-keyboard-overlapping-entry
Below library solved my issue. https://github.com/TheEightBot/Xamarin.IQKeyboardManager
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
IQKeyboardManager.SharedManager.Enable = true;
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With