UITextView

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值