【问题标题】:Gap between toolbar & picker in?工具栏和选择器之间的差距?
【发布时间】:2017-09-26 15:03:10
【问题描述】:

我遇到了一个奇怪的问题。我使用以下代码创建了 UIPicker。我还使用 IQKeyboardManager 来管理键盘。

let datepicker = UIPickerView()

        datepicker.frame = CGRect(x: 0, y: -10, width: UIScreen.main.bounds.width, height: 200)
        datepicker.backgroundColor = Constants.Colors.blue
        datepicker.tintColor = UIColor.white
        textfieldDropDown.inputView = datepicker
        textfieldDropDown.inputView?.autoresizingMask = .flexibleHeight
        datepicker.delegate = self
        datepicker.reloadAllComponents()

临时解决方案 如果我将高度设置为 220,那么由于高度更高,它不会显示任何间隙。

请告诉我最好的解决方案?

【问题讨论】:

    标签: ios swift toolbar ios11 iqkeyboardmanager


    【解决方案1】:

    datePicker.translatesAutoresizingMaskIntoConstraints = false

    【讨论】:

    • 谢谢,但这对我不起作用,所以我所做的是增加高度
    • 这个帮了我
    【解决方案2】:

    iOS 11 更新了选择器,为了修复它首先改变你的

    [[UIPickerView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 200)]
    

    [UIPickerView new]
    

    也变了

    [[UIToolbar alloc] init]
    

    [UIToolbar new]
    

    【讨论】:

      【解决方案3】:

      不要为 UIPickerView 设置任何框架,只需将其声明为

      let datepicker = UIPickerView()
      

      UIToolbar 也一样,

      let toolBar = UIToolbar()
      

      就是这样!

      【讨论】: