您的位置:首页 > 产品设计 > UI/UE

keyboard和 UITextFiled 之间的处理

2015-10-23 09:07 351 查看
//在 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);

// }];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: