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.
Xamarin Forms - Keyboard covers Entry (text field) on iOS
Asked Answered
Wrap your Entry
elements in a ScrollView
this didn't do anything accept make my entry form really really small. Some explanation would be helpful. –
Cruck
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.
How do you know what the right number is? on my device its seemed to be at the right spot at about 260. –
Cruck
You have to scroll little bit not this much. So use minimum number. And these all are different for various device size. –
Onesided
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.
Please read How to Answer and edit your answer. At the moment, it's not very clear that it's an answer to the question. –
Redevelop
Setting
Orientation="Neither"
did the trick for me. Without that, the size of the ScrollView's contents got messed up. –
Clinkscales 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);
}
© 2022 - 2024 — McMap. All rights reserved.