UIPopoverController:為什么我的彈出窗口沒有出現在我想出現的地方?

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


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:

簡單:一個視圖,我使用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];

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?

接下來會發生什么?彈窗沒有顯示它應該在哪里。如果我傳遞{0,0},它會顯示在屏幕中央,就好像視圖大小是(768,512)。我檢查了所有的視圖維度,它們都是ok的,框架,邊界等等。有人知道我做錯了什么嗎?

2 个解决方案

#1


14  

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.

您給presentPopoverFromRect的CGRect是它將在旁邊(不在里面)顯示彈出窗口的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:

如果你想要彈出窗口出現在一個特定的點上,給它一個矩形,原點為點,尺寸為1 1。所以在presentPopoverFromRect線上的CGRectMake應該是:

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

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

還要確保接觸點相對於inView (self)。查看你的情況)。


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

順便說一下,代碼中還有其他一些錯誤(可能只是問題中的拼寫錯誤):

  • setContentController should be setContentViewController
  • setContentController應該setContentViewController
  • popover.ContentSize should be popover.popoverContentSize
  • 彈出窗口。ContentSize應該popover.popoverContentSize
  • myPopverSize.height should be myPopoverSize.height (but this will be replaced by 1)
  • myPopverSize。高度應該myPopoverSize。高度(但這個將被1取代)

#2


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:

就我而言,這個問題的原因如下。也有可能,您的視圖是一個tableView。所以,當你滾動它並試圖在tableView中顯示UIPopover時,它可能不會顯示。我用這個:

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/03/27/72a0a113b47613703b0cc221766c4480.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com