需求如下:
点击UIButton弹出键盘,键盘的上方还需添加一个输入框(UITextField/UITextView)
定义一个输入框类 在这个类内部定义它自身的show和dismiss方法
func show(inView: UIView) { //inView是他将要显示的父视图
inView.addSubview(self)
snp_makeConstraints { (make) in
make.edges.equalTo(UIEdgeInsetsZero)
}
setNeedsLayout()
layoutIfNeeded()
textView.becomeFirstResponder()
}
func dismiss() {
textView.resignFirstResponder()
}
同时可以订阅键盘的状态来改变他的位置
/**
* 键盘控制
*/
keyboardHelper.keyboardWillChange
.subscribeNext {[unowned self] (info) in
var bottomOffset: CGFloat
switch info.type {
case .Show: bottomOffset = -(SCREEN_HEIGHT - info.frame.origin.y)
case .Hide: bottomOffset = self.inputBar.bounds.size.height
}
self.cons_InputBarBottom?.updateOffset(bottomOffset)
UIView.animateWithDuration(info.duration,
animations: {
if let cc = UIViewAnimationCurve(rawValue: info.animationCurve) {
UIView.setAnimationCurve(cc)
}
self.layoutIfNeeded()
}, completion: { (finished) in
switch info.type {
case .Hide: self.removeFromSuperview()
default:break
}
})
}.addDisposableTo(disposeBag)
2 回答1.1k 阅读
1 回答990 阅读✓ 已解决
1 回答2.7k 阅读
1 回答1.4k 阅读
1.7k 阅读
1 回答1.1k 阅读
1.3k 阅读
http://blog.csdn.net/sy431256...
http://blog.csdn.net/oqqquzi1...
这两篇文章解决了我的问题
设置inputAccessoryView。