mono touch中处理视图过长,输入框被键盘遮挡的问题

本文介绍了一个iOS应用中实现键盘弹出时平移当前视图以保持输入框可见性的方法。通过监听输入框编辑状态,利用UIKit框架中的UIView动画进行视图位置的调整,并在触摸屏幕时隐藏键盘并还原视图位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需要对输入框进行监听,然后用动画将当期视图进行上移.

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 ();
				}
			}
		}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值