1。 multiple lines , contain scrollable content
2。相关属性:
contentInset : UIEdgeInsetsMake ( top , left , bottom , right ) //实际内容距上,左,下,右四个方向的边界的距离 margins
3。相关的键盘监听:
在viewWillAppear中进行注册
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @selector ( handleKeyboardDidShow : )
name :UIKeyboardDidShowNotification object : nil ] ;
。。。name : UIKeyboardWillHideNotification 。。。。
在viewWillDisappear中取消
[ [ NSNotificationCenter defaultCenter ] removeObserver : self ] ;
实际执行:
- (void) handleKeyboardDidShow : (NSNotification *) paramNotification {
NSValue *keyboardRectAsObject = [ [ paramNotification userInfo ]
objectForKey : UIKeyboardFrameEndUserInfoKey ] ; // Get the frame of the keyboard
CGRect keyboardEndRect = CGRectZero ; // Place it in a CGRect
[ keyboardRectAsObject getValue : &keyboardEndRect ] ;
//重点:坐标转换
UIWindow *window = [[[UIApplication sharedApplication] delegate] window ] ;
keyboardEndRect = [ self.view convertRect : keyboardEndRect fromView:window ] ;
CGSize kbSize = keyboardEndRect.size;
self.myTextView.contentInset = UIEdgeInsetsMake(0.0f,0.0f, kbSize.size.height, 0.0f);
//设置下边界的margin为一个键盘的高度
}
- (void) handleKeyboardWillHide : (NSNotification *) paramNotification {
self.myTextView.contentInset = UIEdgeInsetsZero ; //恢复初始状态
}
p.s. 键盘通知 包含一个字典,此字典通过userInfo来访问,其中UIKeyboardFrameEndUserInfoKey包含了屏幕上显现的键盘的CGSize