iOS 8 - UIPopoverPresentationController moving popover

后端 未结 6 1290
遇见更好的自我
遇见更好的自我 2020-12-25 13:40

I am looking for an effective way to re-position a popover using the new uipopoverpresentationcontroller. I have succesfully presented the popover, and now I want to move it

6条回答
  •  醉梦人生
    2020-12-25 14:19

    Here is an example for how to recenter the popover:

    - (void)popoverPresentationController:(UIPopoverPresentationController *)popoverPresentationController willRepositionPopoverToRect:(inout CGRect *)rect     inView:(inout UIView **)view {
    
         *rect = CGRectMake((CGRectGetWidth((*view).bounds)-2)*0.5f,(CGRectGetHeight((*view).bounds)-2)*0.5f, 2, 2);
    

    I have also used this method to ensure that the popover moved to the correct location after moving by setting the *rect and the *view to the original sourceRect and sourceView.

    As an additional note, I don't believe that this method is called when the popover's source is set using a bar button item.

提交回复
热议问题