输入框和键盘弹出的适当处理;

//在 viewDidLoad注册通知监听keyboard 的弹出

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];

 

//键盘改变 frame 的时候会调用地方法;

- (void)KeyboardWillChangeFrame:(NSNotification *)noti {

    NSLog(@"%@",noti);

    //设置窗口的颜色;

    self.view.window.backgroundColor = [UIColor whiteColor];

    //取出键盘弹出用的时间;

    CGFloat durtion = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    //键盘最后的 frame

    CGRect keyFrame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

//键盘在 view 上高度的变化;

    CGFloat tranformH = keyFrame.origin.y - self.view.frame.size.height;

//改变时动画延时;

    [UIView animateWithDuration:durtion animations:^{

        self.view.transform = CGAffineTransformMakeTranslation(0, tranformH);

    }];

}

 //在 tableView 滑动的时候 keyboard 隐藏,此时要遵循 scrollerViewDelegate;(uitableVIewDetelate 也行)

#pragma scrollerViewDelegate;

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {

    //结束编辑, keyboard 回收;

    [self.view endEditing:YES];

    //[UIView animateWithDuration:0.25 animations:^{

       // self.view.transform = CGAffineTransformMakeTranslation(0, 216);

  //  }];

}

 

posted @ 2015-10-23 09:03  Chen同学最近很忙  阅读(69)  评论(0编辑  收藏  举报