UIPopoverController Anchor Position

2019-08-08 03:23发布

I have a UIPopOverController for which the content controller is a UINavigationController. I'm resizing the popover size according to the content size of the controller pushed/popped into it. Initally i'm presenting the popover by using the method presentPopoverFromRect:inView:permittedArrowDirections:animated:. The anchor position is pointing at the center of the rect which i passed as an argument. If i push a controller(whose content size is small) into the navigationController , the popover shrinks from the bottom and moves above the rect which i mentioned earlier.

I tried to present the popover everytime(for push/pop) , anchor position remains @ same point But the animation gets affected , doesnt looks good.

what needs to be done to make the anchor position remains same irrespective of the change in popover size variation ?

2条回答
对你真心纯属浪费
2楼-- · 2019-08-08 03:33

I've encountered the same issue and it seems that calling the presentPopoverFromRect method again will keep the anchor at the same position

e.g.

[self.myPopOver presentPopoverFromRect:rectOrigin inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];

Hope it works in your case as well

查看更多
3楼-- · 2019-08-08 03:51

Change frame after presenting UIPopoverController:

 [popupController presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:0 animated:YES];

CGRect popupFrame = popupController.contentViewController.view.superview.superview.superview.frame;
popupFrame.origin.y = btn.frame.origin.y + btn.frame.size.height+75;

popupController.contentViewController.view.superview.superview.superview.frame = popupFrame;
查看更多
登录 后发表回答