Forum Xamarin Xamarin.iOS

Keyboard hide automatically when we work with multiple view.

sumitmishrasumitmishra Member ✭✭✭

Hi,
We have two search textbox that will dynamically showing. One for portrait view and second for landscape view. We handled input text using flag in ViewDidLayoutSubviews() method. We have written a keyboard hide notification method as KeyboardWillHide(NSNotification notification) for text value handling.

We are getting these issue. Please have a look
1. When we start typing ViewDidLayoutSubviews() method every time call on key press and reload textbox. So my keyboard unable to up. We have fixe this with checking a flag if keyboard will then return.
2. Now we are getting same issue that keyboard hide automatic when we press on mic for speak to write. KeyboardWillHide(NSNotification notification) method every time call and hide keyboard. Its also call when we touch on tableview.

How to solve these issue ,Please help. here is my code

private void KeyboardWillHide(NSNotification notification)
{

        string orientation = this.InterfaceOrientation.ToString();
        if ((orientation.ToString() == "Portrait" || orientation.ToString() == "PortraitUpsideDown") && KeyboardHideSameView == false )
        {

            SearchText= txtSearchKeywordLS.Text;
            txtSearchKeyword.Text = txtSearchKeywordLS.Text;

        }
        else if ((orientation.ToString() == "LandscapeRight" || orientation.ToString() == "LandscapeLeft") && KeyboardHideSameView == false )
        {
            SearchText = txtSearchKeyword.Text;
            txtSearchKeywordLS.Text = txtSearchKeyword.Text;

        }

        txtSearchKeyword.ResignFirstResponder();
        txtSearchKeywordLS.ResignFirstResponder();
        isKeyboardApear = false;
        KeyboardHideSameView = false;
    }

public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();

        if (isKeyboardApear == true) return;
        applyViewGradient();

        var orientation = this.InterfaceOrientation;

        if (orientation.ToString() == "Portrait" || orientation.ToString() == "PortraitUpsideDown")
        {
            PortraitConst(this.View.Bounds.Height, this.View.Bounds.Width);

            this.vwLandscapeHead.Hidden = true;
            this.vwPortraitHead.Hidden = false;

            this.txtSearchKeyword.Text = SearchText;

            txtSearchKeyword.ResignFirstResponder();
            txtSearchKeywordLS.ResignFirstResponder();
        }
        else if (orientation.ToString() == "LandscapeRight" || orientation.ToString() == "LandscapeLeft")
        {
            //Console.WriteLine("Landscape Mode");


           // this.addSubview(landscapeView, containerView);

            LandscapeConst(UIScreen.MainScreen.Bounds.Height, UIScreen.MainScreen.Bounds.Width);

            applyViewGradient();

            this.vwPortraitHead.Hidden = true;
            this.vwLandscapeHead.Hidden = false;

            this.txtSearchKeywordLS.Text = SearchText;

            txtSearchKeyword.ResignFirstResponder();
            txtSearchKeywordLS.ResignFirstResponder();
        }
       // this.containerView.NeedsUpdateConstraints();

    }
Tagged:

Posts

  • sumitmishrasumitmishra Member ✭✭✭

    FYI we have fixed this by updating SearchText variable on text changed event for both textbox every key press.

    bool TxtSearchKeyword_ShouldChangeCharacters(UITextField textField, NSRange range, string replacementString)
    {
    SearchText = txtSearchKeyword.Text;
    SearchText = SearchText + "" + replacementString;
    return true;
    }

    bool TxtSearchKeywordLS_ShouldChangeCharacters(UITextField textField, NSRange range, string replacementString)
    {
    SearchText = txtSearchKeywordLS.Text;
    SearchText = SearchText + "" + replacementString;
    return true;
    }

Sign In or Register to comment.