需要对输入框进行监听,然后用动画将当期视图进行上移.
NSNotificationCenter.DefaultCenter.AddObserver (UITextView.TextDidBeginEditingNotification, (notity) => {
InvokeOnMainThread (() => {
//Tools.Alert ("do");
UIView.BeginAnimations ("answerviewanimation2");
this.View.Center = new PointF (rf.Width / 2, rf.Height / 2 - 215);
UIView.CommitAnimations ();
});
});/// <summary>
/// 隐藏键盘
/// </summary>
public override void TouchesBegan (NSSet touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
UITouch touch = touches.AnyObject as UITouch;
if (touch != null) {
if (!utxt.Frame.Contains (touch.LocationInView (this.View))) {
utxt.ResignFirstResponder ();
//视图下移
UIView.BeginAnimations ("answerviewanimation2");
float _t = Tools.IsSdk7 () ? 0 : 44;
this.View.Center = new PointF (rf.Width / 2, (rf.Height + 44) / 2 - _t);
UIView.CommitAnimations ();
}
}
}
本文介绍了一个iOS应用中实现键盘弹出时平移当前视图以保持输入框可见性的方法。通过监听输入框编辑状态,利用UIKit框架中的UIView动画进行视图位置的调整,并在触摸屏幕时隐藏键盘并还原视图位置。
3万+

被折叠的 条评论
为什么被折叠?



