Resize a UI Popover Presentation Controller after orientation change?

Hi. I have a popoverViewController. I have manage to fix everything I want ,except of changing the size when the iphone change the orientation.

The popUp actually works correctly( correct size) when it showed on the current orientation that it is but when the orientation changes, it keeps the size the first time showed.

On Apple documentation of UIPopoverPresentationControllerDelegate they mention popoverPresentationController(_:willRepositionPopoverTo:in:)

I am not sure if this is the correct one but for some Reason this delegate method NEVER runs and I can’t figure out how it works.

the rest of the delegate methods that I am using they work perfect.

Is this the correct approach or should I use something else?
Any Idea ?

thanks a lot

func popoverPresentationController(_ popoverPresentationController: UIPopoverPresentationController, willRepositionPopoverTo rect: UnsafeMutablePointer<CGRect>, in view: AutoreleasingUnsafeMutablePointer<UIView>) {
        
        if popoverPresentationController.presentingViewController is PopUpTextPickerViewController{
            let viewFrame = popoverPresentationController.presentingViewController.view.frame
            
            let newRect = CGRect(x: viewFrame.origin.x, y: viewFrame.origin.y, width: self.view.bounds.width, height: 100)
            let newView = UIView(frame: newRect)
            rect.pointee =  newRect
            view.pointee = newView
            
        }
        print("popoverPresentation:willRepositionPopOverTo")
    }
    
    //Shows the PopUpTextPickerViewController on the screen
    @IBAction func fontButtonPressed(_ sender: UIBarButtonItem) {
        
        subscribeToNotifications(notification: .popUpTextPickerViewController)
        let fontController = storyboard?.instantiateViewController(withIdentifier: "popUpTextPickerViewController") as! PopUpTextPickerViewController
        fontController.fontName = self.fontName
        fontController.fontSize = self.fontSize
        fontController.modalPresentationStyle = UIModalPresentationStyle.popover
        fontController.popoverPresentationController?.delegate = self
        fontController.popoverPresentationController?.barButtonItem = fontButton
        fontController.popoverPresentationController?.backgroundColor = .clear
        fontController.popoverPresentationController?.sourceView = self.view
        fontController.preferredContentSize = CGSize(width: self.view.bounds.width, height: 100)
        present(fontController, animated: true, completion: nil)
    }

This topic was automatically closed after 166 days. New replies are no longer allowed.