本文共 2241 字,大约阅读时间需要 7 分钟。
转载自: http://blog.csdn.net/chang6520/article/details/7921181
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//将popover与tableview视图相关联
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];
最后需要注意的是iPad的状态栏20个像素,导航栏44个像素,如果不准确的话,考虑一下二者的因素。一般情况下如果能准确定位图中的三角箭头的顶角的坐标,直接就用它作为前两个参数,而后两个参数为0就可以了,这就把矩形缩小为一个点了,也是正确的。Over!