TMTBO / TTADataPickerView

A Swift picker view allow you to pick the titles you want and the date, time or dateTime in one view
MIT License
35 stars 9 forks source link

Doesn't work on iOS 13. #5

Open sherwinzadeh opened 4 years ago

sherwinzadeh commented 4 years ago

Seems like this doesn't work on iOS 13. It could be due to iOS 13's new stacked modal view controllers. I am presenting from a modal view controller that has Form Sheet presentation. I tried from Full Screen and it's the same issue. Debugging the UI shows that the UIDatePicker has width and height of 0.

Mfk759853063 commented 4 years ago

yes, i have same problem on iOS 13

Mfk759853063 commented 4 years ago

@sherwinzadeh are you fix this problem?

Mfk759853063 commented 4 years ago

@sherwinzadeh i fixed this bug, like this: `public func showPickerView(ttpickerView: TTADataPickerView, completion: (() -> Void)? = nil) {

    // Get the top viewController
    self.pickerView = ttpickerView
    var topController = UIApplication.shared.keyWindow?.rootViewController
    while (topController?.presentedViewController != nil) {
        topController = topController?.presentedViewController
    }
    topController?.resignFirstResponder()

    // Put the pickerView at the bottom of the screen
    ttpickerView.frame.origin.y = view.bounds.size.height
    view.addSubview(ttpickerView)

    // Set this controller as a childViewController of the topController,
    // Add put it's view as a subView of the topController's view
    view.frame = CGRect(x: 0, y: 0, width: topController?.view.bounds.width ?? 0, height: topController?.view.bounds.height ?? 0)
    view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    topController?.addChildViewController(self)
    topController?.view.addSubview(self.view)

    if #available(iOS 13.0, *) {
        self.fixDisplayBug(ttpickerView: ttpickerView)
    }
    // Show anmiation
    UIView.animate(withDuration: 0.25, delay: 0, options: UIView.AnimationOptions.beginFromCurrentState, animations: {
        self.view.backgroundColor = UIColor(white: 0.0, alpha: 0.5)
        ttpickerView.frame.origin.y = self.view.bounds.size.height - ttpickerView.frame.size.height
    }) { (_) in
        guard let handle = completion else { return }
        handle()
    }
}

private func fixDisplayBug(ttpickerView: TTADataPickerView) {

    var pickerFrame = ttpickerView.pickerView?.frame
    pickerFrame?.size.width = UIScreen.main.bounds.width
    ttpickerView.pickerView?.frame = pickerFrame ?? CGRect.zero

    var datePickerFrame = ttpickerView.datePicker?.frame
    datePickerFrame?.size.width = UIScreen.main.bounds.width
    ttpickerView.datePicker?.frame = datePickerFrame ?? CGRect.zero

    var toolBarFrame = ttpickerView.toolBar.frame
    toolBarFrame.size.width = UIScreen.main.bounds.width
    ttpickerView.toolBar.frame = toolBarFrame
}`
sherwinzadeh commented 4 years ago

Thanks!

bob2077 commented 4 years ago

didClickConfirmButton (TTADataPickerView.swift:497) crash