I'm using a storyboard segue that presents a view controller as popover. The seque has a custom UIView
as its anchor. On pre-iOS9 the popover would correctly point to the centre-bottom of the custom UIView
(presented below the UIView). On iOS9 it points to the top-left corner of the UIView
.
I did try to trace all selector calls to the custom UIView
to find out if there is anything I may need to implement in my custom UIView
to provide the 'hotspot' for the popover but couldn't find anything
Any ideas..? Thanks
Thanks to @Igor Camilo his reply - in case it's useful to some, this is how I fixed this in my code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIPopoverPresentationController* possiblePopOver = segue.destinationViewController.popoverPresentationController;
if (possiblePopOver != nil) {
//
// iOS9 -- ensure correct sourceRect
//
possiblePopOver.sourceRect = possiblePopOver.sourceView.bounds;
}
...
}
Example: 'Short' button triggers a popover, the popover points to the top-left corner of 'Sort' control
Here's an example of Igor Camilo's snippet in Objective-C.
If you reference your popover
UIViewController
in your mainUIViewController
you can adjust thesourceRect
property to offset the popover. For example, given popoverpopoverVC
you can do something like so:Here's my solution, inside
prepareForSegue
:This will move the pointer to the bottom middle of the anchor view
I had the exact same problem. I just resolved it by setting sourceRect in prepareForSegue:
I also encountered this problem but now it works when I added this to my PrepareForSegue function. Given that my Segue ID contains string Popover
Try to set width and height anchor of your source rect (UIView or UIBarButtonItem ) and set it to active .Set it when you are initialising your UIView or UIBarButtonItem.
UIBarButtonItem
UIView