【发布时间】:2016-04-08 23:34:15
【问题描述】:
super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: Selector("hideKeyboard"))
tapGesture.cancelsTouchesInView = true
scrlView.addGestureRecognizer(tapGesture)
//self.navigationController!.navigationBarHidden = true
scrlView.contentSize = CGSizeMake(UIScreen .mainScreen().bounds.size.width, (regButton.frame.size.height + regButton.frame.origin.y)+20)
// Do any additional setup after loading the view.
}
func hideKeyboard() {
scrlView.endEditing(true)
scrlView .setContentOffset(CGPointMake(0, 0), animated: true)
}
@IBAction func tapped(sender: AnyObject) {
scrlView.endEditing(true)
scrlView .setContentOffset(CGPointMake(0, 0), animated: true)
}
我的 hideKeyboard 功能没问题。但是现在我想在点击它们时改变键盘上方文本字段的位置。
【问题讨论】:
-
当文本字段开始编辑然后它应该向上滚动时,你到底需要什么意思??
-
完全正确.. @Shubhambairagi
-
那么你需要做的是设置委托
textFieldShouldReturn。此处为 scrollview 设置 contant 偏移量。并在 tapGausture 上再次重置。见下面我的回答 -
答案在哪里?
标签: ios swift uiscrollview uitextfield