UIPopoverController:为什么我的弹出窗口没有出现在我想要的地方?
简单的: 一个视图,我使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您提供给 presentPopoverFromRect 的 CGRect 是将在其旁边(而不是中)显示弹出框的矩形。根据矩形的位置,弹出框将出现在指定矩形的适当一侧。
如果您希望弹出框出现在特定点,请给它一个以原点为点、大小为 1,1 的矩形。因此,presentPopoverFromRect 行中的 CGRectMake 应该是:
还要确保 touchPoint 相对于 inView (在您的情况下是 self.view )。
顺便说一句,代码中还有一些其他错误(可能只是问题中的拼写错误):
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:
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):
就我而言,这个问题的原因如下。您的视图也有可能是 tableView。因此,当您滚动它并尝试在该 tableView 的矩形中显示 UIPopover 时,它可能不会显示。我用过这个:
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: