ios 键盘覆盖UI问题
2014-10-09 14:50
274 查看
在通知中心添加如下俩个通知,
//键盘显示
NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.DidShowNotification, KeyBoardUpNotifiaction);
//键盘隐藏
NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.DidHideNotification, keyBoardDownNotification);
//键盘显示
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 (); }
相关文章推荐
- ios 键盘覆盖UI问题
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios 手写键盘闪退问题 UIKBBlurredKeyView candidateList
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案
- ios 手写键盘闪退问题 UIKBBlurredKeyView candidateList
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)(转载)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- IOS学习笔记36—解决键盘遮挡输入框(UITextField)问题
- IOS开发 textField 键盘遮挡问题
- IOS开发键盘弹出时遮住输入框的问题
- 打开键盘遮住View的问题解决方法-IOS开发