我在ViewController中有以下内容:
a)长视图滚轮(1000高度)
b)这个long viewScroller包含一个1000高度的UIView,称之为1stView
c)在第一个UIView(1000 Height)中,它包含另一个UiView(称为2ndView)
d)在这个2ndUIView(大小:W300x H290)中,它包含5个textFields。
问题:
1)当用户点击任意一个textFields输入数据时,如何将5个textFields移动到键盘上方?
问题(v1)如下
2)下面的问题代码(V2)
当在外面点击(2ndView或在2ndView中)时,键盘不会消失。
class ItemViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textField1: UITextField!
@IBOutlet weak var textField2: UITextField!
@IBOutlet weak var textField3: UITextField!
@IBOutlet weak var textField4: UITextField!
@IBOutlet weak var textField5: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
textField1.delegate = self
textField2.delegate = self
textField3.delegate = self
textField4.delegate = self
textField5.delegate = self
}
//-(V1)- handle textfield
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
func textFieldDidBeginEditing(textField: UItextField) {
}
func textFieldDidEndEditing(textField: UITextField) {
}
//-(V2) Called when the user click on the view (outside the UITextField).
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
}
由于