Xamarin Forms - Keyboard covers Entry (text field) on iOS
Asked Answered
C

4

8

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.

Competitive answered 15/7, 2018 at 0:58 Comment(0)
V
4

Wrap your Entry elements in a ScrollView

Vivacious answered 15/7, 2018 at 2:44 Comment(1)
this didn't do anything accept make my entry form really really small. Some explanation would be helpful.Cruck
O
4

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.

Onesided answered 16/7, 2018 at 4:29 Comment(2)
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
P
3

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.

Presignify answered 13/4, 2021 at 2:41 Comment(2)
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
A
1

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);
}
Affix answered 3/2, 2020 at 3:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.