UIPopoverController:为什么我的popover没有出现在我想要的地方? [英] UIPopoverController: Why my popover doesn't appears where i want to?

查看:100
本文介绍了UIPopoverController:为什么我的popover没有出现在我想要的地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单:
一个视图,我使用presentPopoverFromRect ...
在CGRect中呈现UIPopoverController,并且箭头或弹出框架都不会出现在我通过的矩形中我要求的坐标附近成。
任何线索?
我一直试图弄清楚这一点,但我放弃了。下面是代码:

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];

接下来会发生什么?弹出窗口没有显示它应该在哪里。如果我通过{0,0}它会在屏幕中间显示,就好像视图大小是(768,512)。我检查了所有视图尺寸,它们都没问题,框架,边界等等。有谁知道我做错了什么?

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?

推荐答案

你给presentPopoverFromRect的CGRect是它将显示popover的矩形 next to( in )。根据rect的位置,popover将出现在指定rect的适当一侧。

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.

如果你想让popover出现在特定的一点,给它一个以原点为点,大小为1,1的矩形。因此,presentPopoverFromRect行中的CGRectMake应为:

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)

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

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应该是setContentViewController

  • popover.ContentSize应该是popover.popoverContentSize

  • myPopverSize.height应该是myPopoverSize.height(但这将被1替换)

这篇关于UIPopoverController:为什么我的popover没有出现在我想要的地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆