您的位置:首页 > 产品设计 > UI/UE

ios 键盘覆盖UI问题

2014-10-09 14:50 274 查看
在通知中心添加如下俩个通知,

//键盘显示

NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.DidShowNotification, KeyBoardUpNotifiaction);

//键盘隐藏

NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.DidHideNotification, keyBoardDownNotification);

UIView activeView;
float scroll_amount=0.0f;
float bottom=0.0f;
float offset=20.0f;
bool moveViewUp=false;
/// <summary>
/// 获取相应控件的view
/// </summary>
/// <param name="main_view">Main view.</param>
void GetActiveView(UIView main_view)
{
foreach (var view in main_view.Subviews) {
if (<span style="font-family: Arial, Helvetica, sans-serif;">view</span>.IsFirstResponder) {
activeView = view;
}

}

}

void KeyBoardUpNotifiaction(NSNotification notification)
{
RectangleF r = UIKeyboard.BoundsFromNotification (notification);
GetActiveView (this.View);
if (activeView==null) {
return;
}
bottom = (activeView.Frame.Y+activeView.Frame.Height+offset);

if (scroll_amount>0) {
return;
}

scroll_amount = (r.Height-(View.Frame.Size.Height-bottom));

if (scroll_amount > 0) {
moveViewUp = true;
scrollTheView( moveViewUp);
} else {
moveViewUp = false;
}
}

void keyBoardDownNotification(NSNotification notifiaction)
{
if (moveViewUp||scroll_amount>0f) {
scrollTheView (false);
}
}

void scrollTheView(bool move)
{
UIView.BeginAnimations (string.Empty, System.IntPtr.Zero);
UIView.SetAnimationDuration (0.3);
RectangleF frame = this.ui_view.Frame;
if (move) {
frame.Y -= (scroll_amount);
} else {
frame.Y += (scroll_amount);
scroll_amount = 0;
}
this.ui_view.Frame = frame;
UIView.CommitAnimations ();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐