我看了几个选项,如:
* http://blog.waynehartman.com/archive/2012/01/07/uistoryboard-on-ios-5-the-good-the-bad-and-the.aspx * UIPopoverController Anchor Position * Can I change the UIPopover animation anchor point?
我正在尝试在mapview中显示地图注释的弹出窗口。目前我正在使用解决方法。我在故事板视图控制器中创建了一个视图,并将我的popover锚定到该视图。我将视图移动到正确的位置,然后使用:
加载弹出窗口(a)找到注释的位置
CGPoint annotationPoint = [_mapView convertCoordinate:self.selectedAnnotationView.annotation.coordinate toPointToView:_mapView];
float boxDY= annotationPoint.y;
float boxDX= annotationPoint.x;
CGRect box = CGRectMake(boxDX,boxDY,1,1);
(b)将我在故事板中创建的视图(anchorView)移动到注释位置
anchorView.frame = box;
(c)显示popover
[annotationPopoverController presentPopoverFromRect:box inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
我的直觉是不需要这种解决方法。有没有更简单,更优雅的方式来做到这一点?
谢谢, 马赫什
答案 0 :(得分:1)
谢谢安娜。为重复发布道歉 - Stackoverflow标记有点麻烦。
我使用segues来启动弹出窗口 - 因此我无法正确定位弹出窗口。
我相信如果您使用segues,我使用的解决方法适合定位popover。
话虽如此,我现在正在使用你答案建议的方法。
我使用
启动弹出窗口self.detailsPopover = [[self storyboard] instantiateViewControllerWithIdentifier:@"identifierName"];
//... config code for the popover
UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:detailsPopover];
//... store popover view controller in an ivar
[self.annotationPopoverController presentPopoverFromRect:selectedAnnotationView.bounds inView:selectedAnnotationView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
答案 1 :(得分:0)
我使用表格和动态锚点创建了类似的答案。在我的解决方案中,您可以使用segue保留故事板的流程。您必须稍微调整一下答案,但基本相同。
Is it possible to perform a Popover Segue manually (from dynamic UITableView cell)?
答案 2 :(得分:0)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let identifier = segue.identifier {
switch identifier {
case "popover":
if let vc = segue.destination as? MyTemplateTableViewController, let ppc = vc.popoverPresentationController {
ppc.permittedArrowDirections = .up
ppc.delegate = self
// set the sourceRect and sourceView to move the anchor point
ppc.sourceRect = ((sender as? UITextField)?.frame)!
ppc.sourceView = sender as? UITextField
}
break
default:
break
}
}
}