我在该表下的单元格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 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
}
}