UIPopoverController:为什么我的弹出窗口没有出现在我想要的地方?

发布于 2024-10-27 09:40:54 字数 1157 浏览 7 评论 0原文

简单的: 一个视图,我使用presentPopoverFromRect在CGRect中呈现一个UIPopoverController... 并且箭头或弹出框都没有出现在我传入的矩形中要求的坐标附近。 有什么线索吗? 我一直试图自己解决这个问题,但我放弃了。代码如下:

if(!myContentController){
    myContentController = [[MyContentController alloc] initWithNibName:myNibName bundle:[NSBundle mainBundle]];
    // This works pretty well. actually when i show the popover
    // i see everything inside as it's supposed to.
}
if(!popover){
   popover = [[UIPopoverController alloc] initWithContentViewController:myContentController];
}
else{
    [popover setContentController:myContentController];
}
popover.delegate = self;
CGPoint touchPointInView = [self touchPoint];//This is working fine too.I've been checking with NSLog.
popover.ContentSize = myPopoverSize;//In this case {320,480}
 [popover presentPopoverFromRect:CGRectMake(touchPoint.x,touchPoint.y,myPopoverSize.width,myPopverSize.height)
                          inView:self.view
        permittedArrowDirections:UIPopoverArrowDirectionAny
                        animated:YES];

接下来会发生什么?弹出窗口没有显示它应该在的位置。如果我传递 {0,0} 它会显示在屏幕中间,就好像视图大小为 (768,512) 一样。我检查了所有视图尺寸,它们都正常,框架,边界等......。有谁知道我做错了什么?

Simple:
A view, i present a UIPopoverController in a CGRect using presentPopoverFromRect...
and neither the arrow or the popover frame appear even near to the coordinates i asked for in the rect i passed into.
Any clues?
I've been trying to figure out this by myself but am giving up. Here is the code:

if(!myContentController){
    myContentController = [[MyContentController alloc] initWithNibName:myNibName bundle:[NSBundle mainBundle]];
    // This works pretty well. actually when i show the popover
    // i see everything inside as it's supposed to.
}
if(!popover){
   popover = [[UIPopoverController alloc] initWithContentViewController:myContentController];
}
else{
    [popover setContentController:myContentController];
}
popover.delegate = self;
CGPoint touchPointInView = [self touchPoint];//This is working fine too.I've been checking with NSLog.
popover.ContentSize = myPopoverSize;//In this case {320,480}
 [popover presentPopoverFromRect:CGRectMake(touchPoint.x,touchPoint.y,myPopoverSize.width,myPopverSize.height)
                          inView:self.view
        permittedArrowDirections:UIPopoverArrowDirectionAny
                        animated:YES];

What happens next? the popover doesn't shows where it should be. If i pass {0,0} it shows in the middle of the screen as if the view size were (768,512). I checked all the view dimensions and they are all ok, frame,bounds, etc... . Does anyone knows what am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行至春深 2024-11-03 09:40:54

您提供给 presentPopoverFromRect 的 CGRect 是将在其旁边(而不是)显示弹出框的矩形。根据矩形的位置,弹出框将出现在指定矩形的适当一侧。

如果您希望弹出框出现在特定点,请给它一个以原点为点、大小为 1,1 的矩形。因此,presentPopoverFromRect 行中的 CGRectMake 应该是:

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

还要确保 touchPoint 相对于 inView (在您的情况下是 self.view )。

顺便说一句,代码中还有一些其他错误(可能只是问题中的拼写错误):

  • setContentController 应该是 setContentViewController
  • popover.ContentSize 应该是 popover.popoverContentSize
  • myPopverSize.height 应该是 myPopoverSize.height (但这将被替换为 1 )

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)
世俗缘 2024-11-03 09:40:54

就我而言,这个问题的原因如下。您的视图也有可能是 tableView。因此,当您滚动它并尝试在该 tableView 的矩形中显示 UIPopover 时,它可能不会显示。我用过这个:

[_popoverController presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文