键盘设置

  • (void)viewDidLoad{
    //监听通知中心
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
    //设置做边距
    self.inputView.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
    //一直显示
    self.inputView.leftViewMode = UITextFieldViewModeAlways;
  • (void)keyboardDidChangeFrame:(NSNotification *)noti{
    NSLog(@”——–%@”,noti.userInfo);
    //改变window的背景颜色
    self.view.window.backgroundColor = self.tableView.backgroundColor;
    // 键盘退出的frame
    CGRect frame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    //键盘实时y
    CGFloat keyY = frame.origin.y;
    //屏幕的高度
    CGFloat screenH = [[UIScreen mainScreen] bounds].size.height;
    //动画时间
    CGFloat keyDuration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
    //执行动画
    [UIView animateWithDuration:keyDuration animations:^{
    self.view.transform = CGAffineTransformMakeTranslation(0, keyY - screenH);
    }];
    }
    //当tableview 滚动的时候 结束编辑事件 (退出键盘)
  • (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
    }

// UIKeyboardAnimationCurveUserInfoKey = 7; 动画曲线动画
// UIKeyboardAnimationDurationUserInfoKey = “0.25”; 动画时间
// UIKeyboardBoundsUserInfoKey = “NSRect: {{0, 0}, {320, 216}}”; 键盘bounds
// UIKeyboardCenterBeginUserInfoKey = “NSPoint: {160, 588}”; 开始键盘的居中位置
// UIKeyboardCenterEndUserInfoKey = “NSPoint: {160, 372}”;结束键盘的居中位置
// UIKeyboardFrameBeginUserInfoKey = “NSRect: {{0, 480}, {320, 216}}”; 键盘开始弹出的frame
// UIKeyboardFrameChangedByUserInteraction = 0; 键盘改变frame
// UIKeyboardFrameEndUserInfoKey = “NSRect: {{0, 264}, {320, 216}}”; 退出键盘的frame

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值