当用户点击它以开始编辑时,我试图将我的UITextView移动到屏幕的上半部分。然后,当用户完成后,UITextView将返回到原始位置。当我运行代码并点击UITextView
时,它会移动到新位置,然后立即返回。在用户完成编辑之前,我没有做什么让UITextField
保持新的位置?我正在使用Xcode 7.0.1和Swift2。谢谢。
import UIKit
class ViewController: UIViewController, UITextFieldDelegate, UITextViewDelegate {
@IBOutlet var textViewField: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
textViewField.layer.cornerRadius = 10
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
func textViewDidBeginEditing(textView: UITextView) {
UIView.animateWithDuration(1) { () -> Void in
self.textViewField.center = CGPointMake(self.textViewField.center.x, self.textViewField.center.y + 400)}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}