`
反求诸己
  • 浏览: 533994 次
  • 性别: Icon_minigender_1
  • 来自: 湖南娄底
社区版块
存档分类
最新评论

打开键盘遮住View的问题解决方法1-IOS开发

 
阅读更多

首先我们要知道键盘的高度是固定不变的,不过在IOS 5.0 以后键盘的高度貌似不是216了,不过不要紧,我们调整调整就是了:

 

  iPhone ipad
竖屏(portrait) 216 264
横屏(landScape) 140 352

我们采取的方法就是在textField(有可能是其他控件)接收到弹出键盘事件时把self.view整体上移216px了(我们就以iPhone竖屏为例了)。

 

    - (void)textFieldDidBeginEditing:(UITextField *)textField  
    { //当点触textField内部,开始编辑都会调用这个方法。textField将成为first responder   
           NSTimeInterval animationDuration = 0.30f;      
          CGRect frame = self.view.frame;  
          frame.origin.y -=216;  
          frame.size.height +=216;  
          self.view.frame = frame;  
           [UIView beginAnimations:@"ResizeView" context:nil];  
           [UIView setAnimationDuration:animationDuration];  
           self.view.frame = frame;                  
           [UIView commitAnimations];                  
    }  
 
    - (BOOL)textFieldShouldReturn:(UITextField *)textField   
    {//当用户按下ruturn,把焦点从textField移开那么键盘就会消失了  
            NSTimeInterval animationDuration = 0.30f;  
            CGRect frame = self.view.frame;      
            frame.origin.y +=216;        
            frame.size. height -=216;     
            self.view.frame = frame;  
        //self.view移回原位置    
        [UIView beginAnimations:@"ResizeView" context:nil];  
        [UIView setAnimationDuration:animationDuration];  
            self.view.frame = frame;                  
            [UIView commitAnimations];  
            [textField resignFirstResponder];     
    } 
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics