其更好地利用這一點:你的文本字段的
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
scrollView.scrollEnabled = true
yourTextfield.addTarget(self, action: "textFieldShouldReturn:", forControlEvents: .EditingDidEndOnExit)
yourTextfield2.addTarget(self, action: "textFieldShouldReturn:", forControlEvents: .EditingDidEndOnExit)
...
yourTextfield.tag = 1
yourTextfield2.tag = 2
...
}
func textFieldShouldReturn(textField: UITextField!) -> Bool {
let nextTag = textField.tag + 1
let nextResponder:UIResponder? = textField.superview?.viewWithTag(nextTag)
if ((nextResponder) != nil) {
nextResponder?.becomeFirstResponder()
var scrollPoint: CGPoint = CGPointMake(0, textField.frame.origin.y - 50)
scrollView.setContentOffset(scrollPoint, animated: true)
} else {
textField.resignFirstResponder()
scrollView.setContentOffset(CGPointZero, animated: true)
}
return false
}
你是說你不能把它翻譯成Swift,而你想讓其他人爲你做? – matt 2014-12-04 15:33:12
請澄清你的問題。你不知道如何在swift中編寫相同的代碼,或者它沒有按預期工作? – cmyr 2014-12-04 16:45:48
大家好!是的,在目標c中,當鍵盤出現時,這兩行代碼將向上滾動。如何在SWIFT中翻譯此代碼? – 2014-12-06 06:18:00