Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ParentVC: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- view.backgroundColor = .systemYellow
- let childVC = ChildVC()
- self.addChild(childVC)
- childVC.view.frame = .init(x: 60.0, y: 80.0, width: 240.0, height: 160.0)
- childVC.view.autoresizingMask = []
- self.view.addSubview(childVC.view)
- childVC.didMove(toParent: self)
- }
- }
- class ChildVC: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
- let picker = UIPickerView()
- override func viewDidLoad() {
- super.viewDidLoad()
- self.view.addSubview(self.picker)
- self.picker.delegate = self
- self.picker.dataSource = self
- }
- override func viewDidAppear(_ animated: Bool) {
- print(#function)
- super.viewDidAppear(animated)
- if self.view.superview != nil {
- picker.frame = self.view.bounds
- picker.autoresizingMask = []
- } else {
- picker.frame = .init(x: 20.0, y: 100.0, width: 260.0, height: 160.0)
- }
- picker.backgroundColor = .yellow
- }
- override func viewSafeAreaInsetsDidChange() {
- super.viewSafeAreaInsetsDidChange()
- //This gets called everytime the device rotates, causing the picker view to redraw and reload all components. Trying to avoid this method being called.
- print ("viewSafeAreaInsetsDidChange")
- print (self.view.safeAreaInsets)
- }
- func numberOfComponents(in pickerView: UIPickerView) -> Int {
- print(#function)
- return 1
- }
- func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
- print(#function)
- return 30
- }
- func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
- print(#function, "Row:", row)
- return "Row: \(row)"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement