您的位置:首页 > 移动开发 > IOS开发

iOS 自定义键盘ToolBar(与键盘的弹出、收起保持一致)

2016-11-30 18:32 495 查看
1、监听键盘改变的通知

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


2、实现通知方法

/**

*  给键盘的frame改变添加监听

*  @param keyBoardWillChangeFrame: 监听方法

*/

- (void)keyBoardWillChangeFrame:(NSNotification*)notification{

// 键盘显示\隐藏完毕的frame

CGRect frame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

// 动画时间

CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

if (frame.origin.y == JYEScreenHeight) { // 没有弹出键盘

[UIView animateWithDuration:duration animations:^{

self.toolBarView.transform =  CGAffineTransformIdentity;

}];

}else{ // 弹出键盘

// 工具条往上移动258

[UIView animateWithDuration:duration animations:^{

self.toolBarView.transform = CGAffineTransformMakeTranslation(0, -frame.size.height-64);

}];

}

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