UIPopoverController: Why my popover doesn't appears where i want to?

烈酒焚心 提交于 2019-12-05 12:06:24

The CGRect you give to presentPopoverFromRect is the rect that it will display the popover next to (not in). Depending on the location of the rect, the popover will appear on an appropriate side of the specified rect.

If you want the popover to appear at a specific point, give it a rect with the origin as the point and the size as 1,1. So the CGRectMake in the presentPopoverFromRect line should be:

CGRectMake(touchPoint.x,touchPoint.y,1,1)

Also make sure that the touchPoint is relative to the inView (self.view in your case).


By the way, there are a few other errors in the code (probably just typos in the question):

  • setContentController should be setContentViewController
  • popover.ContentSize should be popover.popoverContentSize
  • myPopverSize.height should be myPopoverSize.height (but this will be replaced by 1)

In my case the reason of this problem was following. It is also possible, that your view is a tableView. So, when you scroll it and try to show UIPopover in a rect in that tableView, it may not be shown. I used this:

[_popoverController presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!