Moving UIPopoverController to device rotation

I am trying to change the position of a popover when the device is rotated. I am using this code to create a popover:

        settingsViewCtrl = storyboard.instantiateViewControllerWithIdentifier("settingsViewCtrl") as SettingsViewCtrl;
        settingsPopoverCtrl = UIPopoverController(contentViewController: settingsViewCtrl);
        settingsPopoverCtrl.delegate = self;
        let m:CGFloat = min(view.frame.width, view.frame.height);
        let s:CGSize = CGSizeMake(m - 100, m - 100);
        let r:CGRect = CGRectMake(view.frame.width * 0.5, view.frame.height * 0.5, 1, 1);
        settingsPopoverCtrl.setPopoverContentSize(s, animated: true);
        settingsPopoverCtrl.presentPopoverFromRect(r, inView: view, permittedArrowDirections: nil, animated: true);

      

And I am using willRepositionPopoverToRect

in my delegate ...

func popoverController(popoverController:UIPopoverController!, willRepositionPopoverToRect rect:UnsafeMutablePointer<CGRect>, inView view:AutoreleasingUnsafeMutablePointer<UIView?>)
{
    if (settingsPopoverCtrl != nil && settingsViewCtrl != nil)
    {
        let r:CGRect = CGRectMake(self.view.frame.width * 0.5, self.view.frame.height * 0.5, 1, 1);
        settingsPopoverCtrl.presentPopoverFromRect(r, inView: self.view, permittedArrowDirections: nil, animated: true);
    }
}

      

But it can't be because when I rotate the device I get a warning: The app tried to present an active presentation popover: and the popover doesn't move either.

How can I apply and update the CGRect positioning in the willRepositionPopoverToRect file to update the popover? Can I change the one provided rect:UnsafeMutablePointer<CGRect>

and return it back?


UPDATE:

According to the docs ( https://developer.apple.com/library/ios/documentation/uikit/reference/UIPopoverControllerDelegate_protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIPopoverControllerDelegate/popoverController%3awillReposition3Popover ):

If you want to suggest a different rectangle for the popover, supply a new value in this parameter.

So the question is, how do I put the new value into this rectangle?

+3


source to share


1 answer


Let me answer this:

        let r:CGRect = CGRectMake(self.view.frame.width * 0.5, self.view.frame.height * 0.5, 1, 1);
        rect.initialize(r);

      



... will obviously launch the given rectangle with new dimensions, and it works flawlessly when the device rotation is changed, as opposed to the misleading code in Apple docs where they use it again presentPopoverFromRect

, which completely doesn't work.

+5


source







All Articles