mnbayan / AutocompleteTextfieldSwift

Simple and straightforward sublass of UITextfield to manage string suggestions
MIT License
290 stars 66 forks source link

Rotation to landscape issue #23

Closed klauswaiss closed 7 years ago

klauswaiss commented 8 years ago

When the autocomplete tableView is showing with its autocomplete-suggestions and you rotate to landscape, the tableView won't redraw which leads to separator lines that only fill half of the screen width instead of the new screen width from landscape screen.

I wrote a quick workaround, exposing redrawTable in AutoCompleteTextField.swift:

func redrawTable() {

        if let autoCompleteTableView = autoCompleteTableView,

           let autoCompleteTableHeight = autoCompleteTableHeight  {

            var newFrame = autoCompleteTableView.frame

            newFrame.size.height = autoCompleteTableHeight

            let screenSize = UIScreen.mainScreen().bounds.size

            newFrame.size.width = screenSize.width - (self.frame.origin.x * 2)

            autoCompleteTableView.frame = newFrame

        }
}

Then in your ViewController you can do sth like this:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {

    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

    coordinator.animateAlongsideTransition(nil, completion: { _ in

        self.autoCompleteTextField.redrawTable()

    })
}
mnbayan commented 8 years ago

@klauswaiss thanks for the feedback. I will look into it.

ignacio-chiazzo commented 8 years ago

@mnbayan I am getting the same error with the last version, is that fixed or will be fixed soon?

ignacio-chiazzo commented 7 years ago

@klauswaiss Any update? Is that fixed?