![](/img/trans.png)
[英]How to automatically resize a Windows Mobile application when the keyboard appears?
[英]How fix when the keyboard appears?
我在這張表格下的單元格 y 中有一個帶有 textField 的表格我有一個 textField
-------------------------------------------
- --------------------------------------- -
- - text field in table - -
- ------------------------------------- - -
-------------------------------------------
- --------------------------------------- -
- - other textField - -
- ------------------------------------- - -
然后我為鍵盤的入口做了一個庫
public static void KeyBoardUpNotification(NSNotification notification)
{
scrollamount = 0.0f;
RectangleF rectangle = (RectangleF)UIKeyboard.BoundsFromNotification(notification);
if (currentView == null)
{
return;
}
if (activeview==null) {
foreach (UIView view in currentView.Subviews)
{
if (view.IsFirstResponder)
{
activeview = view;
activeview.BecomeFirstResponder();
}
}
}
if (activeview == null)
{
return;
}
bottom = ((float)(activeview.Frame.Y + activeview.Frame.Height + offset));
scrollamount = ((float)(rectangle.Height - (currentView.Frame.Size.Height - bottom)));
if (scrollamount != 0)
{
moveViewUp = true;
ScrollTheView(moveViewUp);
}
else
{
moveViewUp = false;
}
}
public static void KeyBoardDownNotification(NSNotification notification)
{
if (moveViewUp) ScrollTheView(false);
}
private static void ScrollTheView(bool move)
{
UIView.BeginAnimations(string.Empty, IntPtr.Zero);
UIView.SetAnimationDuration(0.3);
RectangleF frame = (RectangleF)currentView.Frame;
if (move)
{
frame.Y = y;
frame.Y -= scrollamount;
}
else
{
frame.Y = y;
scrollamount = 0;
moveViewUp = false;
}
currentView.Frame = frame;
UIView.CommitAnimations();
scrollamount = 0;
frame.Y = 0;
}
但是當焦點位於單元格的文本字段中時,此代碼不起作用,相機會聚焦在下面的文本字段上。
但此代碼僅適用於下面的文本字段,相機聚焦於下面的文本字段,這很好。
您可以將標簽添加到belowTextfield
並將其與activeview
進行比較,然后決定向上移動belowTextField
或tableView
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
UITextField belowTextField = new UITextField();
belowTextField.Tag = 1;
}
public void test() {
if (activeview == null)
{
foreach (UIView view in currentView.Subviews)
{
if (view.IsFirstResponder)
{
activeview = view;
activeview.BecomeFirstResponder();
}
}
}
UITextField tempView = activeview as UITextField;
if (tempView.Tag == 1)
{
//move up bellowTextField
}
else {
//move up tableView
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.