很简单,就是开始输入时把整个view的frame上移,也就是把y值减小就行了,至于减少多少自己调 ,也可以动态获取参见(http://blog.csdn.net/lengshengren/article/details/49010509)。
func textViewDidBeginEditing(textView:UITextView) {
UIView.animateWithDuration(0.4, animations: {
self.view.frame.origin.y = -220
})
}
编辑结束收起键盘是在把view移动下来就行了:
class AddDayReportViewController:UITableViewController,UITextViewDelegate {
@IBOutlet weakvar workcontent: UITextView!
override func viewDidLoad() {
//注册点击事件
view.addGestureRecognizer(UITapGestureRecognizer(target:self, action:"handleTap:"))
}
func handleTap(sender: UITapGestureRecognizer) {
if sender.state == .Ended {
print("收回键盘")
UIView.animateWithDuration(0.4, animations: {
self.view.frame.origin.y = 0
})
workcontent.resignFirstResponder()
}
sender.cancelsTouchesInView =false
}
func textViewDidBeginEditing(textView: UITextView) {
UIView.animateWithDuration(0.4, animations: {
self.view.frame.origin.y = -220
})
}
}
我的输入框名字叫: workcontent