iPad UIPopoverController弹出窗口的位置和坐标

来源:互联网 发布:linux怎样浏览网页 编辑:程序博客网 时间:2024/05/16 15:22
TodoViewController *contentViewController = [[TodoViewController alloc] init];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:contentViewController];
    navigationController.contentSizeForViewInPopover = CGSizeMake(100, 100); //内容大小
    
    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
    popover.popoverContentSize = CGSizeMake(300, 300); //弹出窗口大小,如果屏幕画不下,会挤小的。这个值默认是320x1100
    
    CGRect popoverRect = CGRectMake(200, 700, 10, 10);
    [popover presentPopoverFromRect:popoverRect  //popoverRect的中心点是用来画箭头的,如果中心点如果出了屏幕,系统会优化到窗口边缘
                             inView:self.view //上面的矩形坐标是以这个view为参考的
           permittedArrowDirections:UIPopoverArrowDirectionDown  //箭头方向
                           animated:YES];
    
    [contentViewController release];
    [navigationController release];
    

    //最佳实践,使用哪个view做参考,就以哪个view的bounds送进去就好了,箭头自动指向这个view的中心。

[popover presentPopoverFromRect:((UIView *)tableview).frame//popovertableview视图相关联

                             inView:self.view

           permittedArrowDirections:UIPopoverArrowDirectionUp//箭头方向

                           animated:YES];


popover.popoverContentSize = CGSizeMake(300, 300); //弹出窗口大小。这个没什么好说的,就是大小,当然不能超过屏幕。

[popover presentPopoverFromRect: CGRectMake(x0, y0, x1, y1);

inView:self.view

  permittedArrowDirections:UIPopoverArrowDirectionDown  //箭头方向

  animated:YES];

上面是基本代码,大小没什么可说的。主要是下面这个CGRectMake(x0, y0, x1, y1)函数的四个参数。
先看名字presentPopoverFromRect,from矩形,什么意思,就是说这个popover是出自,来自这个矩形,形象地说就是这个矩形产生出一个用箭头指向的popover.看下面的图,无非这四种情况。这里的四个参数,就是下图中小矩形的参数,大矩形就是
popover。看图就是简单明了,直接了当,不要再说什么矩形中点了,只要确定了小矩形,确定了箭头方向(相对于大矩形),就确定了popover的位置。一般这个小矩形都是button,item什么的。



最后需要注意的是iPad的状态栏20个像素,导航栏44个像素,如果不准确的话,考虑一下二者的因素。一般情况下如果能准确定位图中的三角箭头的顶角的坐标,直接就用它作为前两个参数,而后两个参数为0就可以了,这就把矩形缩小为一个点了,也是正确的。Over!


多个UIPopoverController的切换问题

情况描述:多个button控制对应的UIPopoverController,当一个UIpopverController_A打开的时候,点击button_B去打开另外一个UIPopverContrller_B,每次都需要点击两下才能打开,(我的理解)第一次只是关闭UIpopverController_A,第二次才是打开UIPopverContrller_B。

解决方法:
UIPopoverController * poper...

UIButton * BtnA...

NSArray *array=[NSArray arrayWithObjects:BtnA,BtnB,BtnC,BtnD,BtnE,BtnF,BtnG,BtnH];

poper.passthroughViews=array;

设置passthroughViews为这个数组就可以了~


UIPopoverController如何改变边框颜色?

http://www.cocoachina.com/bbs/simple/?t25154.html
1 0