zoukankan      html  css  js  c++  java
  • ios中键盘处理适合ipad 和iphone

      
      [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardWasShown:)
                                                     name:UIKeyboardDidShowNotification object:nil];
    
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardWasHidden:)
                                                     name:UIKeyboardDidHideNotification object:nil];
    
    =======
    -(void)keyboardWasShown:(NSNotification*)aNotification{
        
        NSDictionary *info=[aNotification userInfo];
    
        CGRect KeyBoardrect=[info[UIKeyboardBoundsUserInfoKey] CGRectValue];
        int curve=[info[UIKeyboardAnimationCurveUserInfoKey] intValue];
        CGFloat duration=[info[UIKeyboardAnimationDurationUserInfoKey] floatValue];
        UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
         UIView *firstResponder = [keyWindow performSelector:@selector(firstResponder)];
         if ([NSStringFromClass([firstResponder class]) isEqualToString:@"UITextView"]) {
    
             CGFloat height=self.view.bounds.size.height;//view的高度
             CGFloat y=self.remarksTextView.frame.origin.y+KHeight;//文本框的高度
             CGFloat keyboardheight=KeyBoardrect.size.height+44;//键盘高度--》中文高度44
             CGFloat h=height-y-keyboardheight;
             NSLog(@"%@--keyboard->",info);
             NSLog(@"height=%f-- -->",height);
             
             if(h<0){
                 [UIView beginAnimations:nil context:nil];
                 [UIView setAnimationCurve:curve];
                 [UIView setAnimationDuration:duration];
                 CGRect rect=self.view.frame;
                 rect.origin.y+=h;
                 self.view.frame=rect;
                 [UIView commitAnimations];
             }
         }
    }
    
    -(void) keyboardWasHidden:(NSNotification*)aNotification
    {
        NSDictionary *info=[aNotification userInfo];
    
        int curve=[info[UIKeyboardAnimationCurveUserInfoKey] intValue];
        CGFloat duration=[info[UIKeyboardAnimationDurationUserInfoKey] floatValue];
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:curve];
        [UIView setAnimationDuration:duration];
        self.view.frame=_lastRect;
        [UIView commitAnimations];
    
    }
  • 相关阅读:
    adb检测不到夜神模拟器
    夜神模拟器相关设置
    dos窗口下查看系统环境变量设置,输出dos命令结果到文件
    JavaScript DOM操作案例列表的高亮显示
    JavaScript DOM操作案例美女相册
    JavaScript DOM操作案例阻止超链接跳转
    JavaScript DOM操作案例点击按钮修改ul背景颜色
    Git 状态 untracked 和 not staged的区别
    GitPython模块简介
    解决error: failed to push some refs to 'xxxx'
  • 原文地址:https://www.cnblogs.com/gcb999/p/3232986.html
Copyright © 2011-2022 走看看