我们有两个动态显示的搜索文本框。一个用于纵向视图,另一个用于横向视图。我们在ViewDidLayoutSubviews()方法中使用标志处理输入文本。我们已经编写了键盘隐藏通知方法作为用于文本值处理的KeyboardWillHide(NSNotification通知)。
我们正在解决这些问题。请看一下1.当我们每次按下按键并重新加载文本框时,我们开始键入ViewDidLayoutSubviews()方法。所以我的键盘无法启动。如果键盘将返回,我们已经通过检查标志来解决这个问题。 2.现在我们遇到同样的问题,当我们按下麦克风说话时,键盘自动隐藏。 KeyboardWillHide(NSNotification notification)方法每次调用和隐藏键盘。当我们触摸tableview时它也会打电话。如何解决这些问题,请帮忙
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();
}
我们通过使用标志逻辑地解决了它。当视图首先出现时,我们声明了一个布尔标志isKeyboardAppear=false
。当键盘出现时我们将此标志设置为true我们注意到ViewDidLayoutSubviews()方法在每次按键时调用,因此我们编写此代码
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
if (isKeyboardAppear == true)
{
return;
}
}
当我们手动隐藏键盘时,我们重置标志isKeyboardAppear = false。