Мне нужна помощь в создании выпадающего меню с таблицей из дочернего контроллера.
Пример кода:
class ParentViewController: UIViewController {
func displayShowCountries() {
if let textField = self.activeTextField, let superview = textField.superview {
let convert = superview.convert(textField.frame, to: self.view)
let row = viewModel.count - 1
let indexPath = IndexPath(row: row, section: 0)
guard let cell = tableView.cellForRow(at: indexPath) else { return }
let cellConvert = tableView.convert(cell.frame, to: self.view)
addChild(selectCountry)
view.addSubview(selectCountry.view)
selectCountry.didMove(toParent: self)
// start frame
selectCountry.view.frame = CGRect(x: convert.origin.x, y: convert.maxY, width: convert.width, height: 0)
let height = (cellConvert.origin.y - convert.origin.y) + 8
UIView.animate(
withDuration: 0.3,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 1,
options: .curveEaseOut,
animations: {
self.selectCountry.view.frame = CGRect(x: convert.origin.x, y: convert.maxY, width: convert.width, height: height)
},
completion: nil)
}
}
}
Для SelectCountry ()
class SelectCountry: UIViewController {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
tableView.frame = view.bounds
}
}
Анимация работает только для selectCountry.view
, но все, что находится в selectCountry.view
, не отображается с анимацией.