![](/img/trans.png)
[英]where are my UIBarButtonItem & UIToolbar on UIPopoverController
[英]UIPopoverController: Why my popover doesn't appears where i want to?
简单:一个视图,我使用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)。 我检查了所有视图尺寸,它们都没问题,框架,边界等等。 有谁知道我做错了什么?
你给presentPopoverFromRect的的CGRect是它旁边会显示一个 ( 不 )的酥料饼的矩形。 根据rect的位置,popover将出现在指定rect的适当侧。
如果您希望弹出窗口出现在特定点,请为其指定一个以原点为点,大小为1,1的矩形。 所以presentPopoverFromRect行中的CGRectMake应该是:
CGRectMake(touchPoint.x,touchPoint.y,1,1)
还要确保touchPoint相对于inView(在您的情况下为self.view)。
顺便说一下,代码中还有一些其他错误(可能只是问题中的拼写错误):
在我的情况下,这个问题的原因如下。 您的视图也可以是tableView。 因此,当您滚动它并尝试在该tableView中的矩形中显示UIPopover时,它可能不会显示。 我用过这个:
[_popoverController presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.