gpt4 book ai didi

ios - Swift,如何将现有的 uiview 转换为 uiscrollview?

转载 作者:搜寻专家 更新时间:2023-11-01 05:46:07 25 4
gpt4 key购买 nike

目前我有一个只有一个 View 的 Storyboard,但我需要再添加 5 个文本字段。所以我喜欢启用垂直滚动。我以为我只需要将 View Controller 的类从 UIView 更改为 UIScrollView:

enter image description here

除了更改类我还应该做什么才能为此 View 启用垂直滚动?我在 viewDidLoad() 中唯一拥有的东西

    override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

// Set date to today
let today = dateToday()
dateInvoice.text = today
}

编辑好的,我让滚动部分工作了,但是隐藏/关闭键盘部分不再工作了。如果用户在 ScrollView 中的文本字段外单击,我如何关闭键盘

    //HIDE KEYBOARD
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
//END HIDE KEYBOARD

编辑 2:由于以下原因,我找到了一个可行的解决方案: Swift UIScrollView : keyboard doesn't dismiss interactively

enter image description here

最佳答案

选择您的文本字段,然后在菜单中:

Editor->Embed in->Scroll view

然后使 ScrollView 大小合适,如果您使用自动布局,请添加所需的约束。

关于ios - Swift,如何将现有的 uiview 转换为 uiscrollview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33127868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com