当我点击文字字段时,我的当前应用程序有效,它会调出UIPickerView
,但如果我自己点击图像(手势放在图像上)会怎么样?
class SomeVC: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var inputLabel: UITextField!
@IBOutlet weak var laImageGestureTapped: UITapGestureRecognizer!
let demoPicker = UIPickerView()
// viewDidLoad()
inputLabel.inputView = demoPicker // All is well with this.
// How to open the UIPickerView with laImageGestureTapped?
// I have omitted the required functions for: numberOfRowsInComponent, viewForRow, didSelectRow, numberOfComponents etc
}
我是searching with the correct words吗?
我想要的只是在点击图像时显示选择器。我并不担心didSelectRow
因为会有一个隐藏的标签来做x,y和z。
如果已经提出并回答了这个问题,请指导我。感谢。
答案 0 :(得分:2)
这是在图像上放置明文字段的另一种方法:
以下是相关代码:
class VC: UIViewController {
var pickerView = UIPickerView()
override func viewDidLoad() {
super.viewDidLoad()
...
pickerView = UIPickerView(frame: CGRect(x: 0, y: self.view.bounds.height, width: self.view.bounds.width, height: 100)) //Step 2
}
@IBAction func buttonPressed(sender: UIButton){ //Step 3
UIView.animate(withDuration: 0.3, animations: {
self.pickerView.frame = CGRect(x: 0, y: self.view.bounds.size.height - self.pickerView.bounds.size.height, width: self.pickerView.bounds.size.width, height: self.pickerView.bounds.size.height)
})
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(doneWithPickerView))
view.addGestureRecognizer(tapGesture)
}
func doneWithPickerView() { //Step 4
UIView.animate(withDuration: 0.3, animations: {
self.pickerView.frame = CGRect(x: 0, y: self.view.bounds.size.height, width: self.pickerView.bounds.size.width, height: self.pickerView.bounds.size.height)
})
}
}
我认为一般来说,不使用隐形视图会更好,因为它们可能会给您的后来造成麻烦。希望这会有所帮助。