gpt4 book ai didi

ios - 使用 Swift,如何禁止弹出键盘?

转载 作者:行者123 更新时间:2023-11-28 06:11:57 25 4
gpt4 key购买 nike

我正在使用 xCode 在 Swift 3.0 中编写应用程序。

当我按下文本框时,我只想显示选择器 View ;那么,为什么键盘会显示呢?如何禁止它弹出?

这是没有触摸文本框的 iPhone: picture one

这是我触摸文本框时的 iPhone:

picture two

这是我的 View Controller 代码:

//the arrays for the height textbox
var heightInFeet = ["4\' 8\"", "4\' 9\"", "4\' 10\"", "4\' 11\"", "5\'", "5\' 1\"", "5\' 2\"", "5\' 3\"", "5\' 4\"", "5\' 5\"", "5\' 6\"", "5\' 7\"", "5\' 8\"", "5\' 9\"", "5\' 10\"", "5\' 11\"", "6\'", "6\' 1\"", "6\' 2\"", "6\' 3\"", "6\' 4\"", "6\' 5\"", "6\' 6\"", "6\' 7\"", "6\' 8\""]
var heightInMeters = ["1.42", "1.44", "1.46", "1.48", "1.5", "1.52", "1.54", "1.56", "1.58", "1.6", "1.62", "1.64", "1.66", "1.68", "1.7", "1.72", "1.74", "1.76", "1.78", "1.8", "1.82", "1.84", "1.86", "1.88", "2.0", "2.2"]
var pickerArray = [String]()

//the array for the activity level textbox
var activityLevel = ["None/Sedentary", "Light/Low", "Moderate/Active", "High/Very Active"]

...

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
var countrows : Int = pickerArray.count

if pickerView == pickerViewForActivityLevel{
countrows = self.activityLevel.count
}
return countrows
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView == pickerViewForHeight{
let titleRowForHeight = pickerArray[row]
return titleRowForHeight
}
else if pickerView == pickerViewForActivityLevel{
let titleRowForActivityLevel = activityLevel[row]
return titleRowForActivityLevel
}
return ""
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if pickerView == pickerViewForHeight{
self.heightTextBox.text = self.pickerArray[row]
self.pickerViewForHeight.isHidden = true
}
else if pickerView == pickerViewForActivityLevel{
self.activityLevelTextBox.text = self.activityLevel[row]
self.pickerViewForActivityLevel.isHidden = true
}
}

func textFieldDidBeginEditing(_ textField: UITextField) {
if (textField == self.heightTextBox){
self.pickerViewForHeight.isHidden = false
}
else if (textField == self.activityLevelTextBox){
self.pickerViewForActivityLevel.isHidden = false
}
}

@IBAction func heightSwitchAction(_ sender: UISwitch) {
if heightUnitsSwitch.isOn{
heightUnits.text = "Feet (ft)"
pickerArray = []
pickerArray.append(contentsOf: heightInFeet)
}
else{
heightUnits.text = "Meters (m)"
pickerArray = []
pickerArray.append(contentsOf: heightInMeters)
}
}

提前致谢。

最佳答案

尝试将 inputView UIView() 设置为 inputView textField.inputView = UIView()

关于ios - 使用 Swift,如何禁止弹出键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46290954/

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