Skip to content

Instantly share code, notes, and snippets.

@nodoid
Last active August 29, 2015 14:23
Show Gist options
  • Save nodoid/5da70ca571d9f9ee05c0 to your computer and use it in GitHub Desktop.
Save nodoid/5da70ca571d9f9ee05c0 to your computer and use it in GitHub Desktop.
Scroll on TextField enter
txtEmail.EditingDidBegin += delegate
{
UIUtils.SetKeyboardEditorWithCloseButton(txtEmail, UIKeyboardType.Default);
UIUtils.AnimateTextField(View, true);
};
txtEmail.EditingDidEnd += delegate
{
UIUtils.AnimateTextField(View, false);
};
public static void AnimateTextField(UIView view, bool direction)
{
int moveDist = 100;
double moveDur = 0.3;
int move = (direction ? -moveDist : 0);
UIView.BeginAnimations("anim");
UIView.SetAnimationBeginsFromCurrentState(true);
UIView.SetAnimationDuration(moveDur);
view.Frame = new CGRect(view.Frame.X, (float)move, view.Bounds.Width, view.Bounds.Height);
UIView.CommitAnimations();
}
public static void SetKeyboardEditorWithCloseButton(UITextField txt, UIKeyboardType keyboardType)
{
var toolbar = new UIToolbar
{
BarStyle = UIBarStyle.Black,
Translucent = true,
};
txt.KeyboardType = keyboardType;
toolbar.SizeToFit();
var text = new UITextView(new CGRect(0, 0, 200, 32))
{
ContentInset = UIEdgeInsets.Zero,
KeyboardType = keyboardType,
Text = txt.Text,
UserInteractionEnabled = true
};
text.Layer.CornerRadius = 4f;
text.BecomeFirstResponder();
var doneButton = new UIBarButtonItem(StringUtils.GetString("Common.Done"), UIBarButtonItemStyle.Done,
(s, e) =>
{
text.ResignFirstResponder();
txt.ResignFirstResponder();
/*if (!string.IsNullOrEmpty(text.Text))
txt.Text = text.Text;*/
});
toolbar.UserInteractionEnabled = true;
toolbar.SetItems(new UIBarButtonItem[]{ doneButton/*, textField*/ }, true);
txt.InputAccessoryView = toolbar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment