【问题标题】:How can I change the anchor point of the UIPopover? PresentFromRect doesn't work correctly for me.如何更改 UIPopover 的锚点? PresentFromRect 对我来说不能正常工作。
【发布时间】:2012-05-12 12:03:54
【问题描述】:

我查看了几个选项,例如:

*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 中显示地图注释的弹出框。目前我正在使用一种解决方法。我在我的故事板视图控制器中创建了一个视图,并将我的弹出框锚定到该视图。我将视图移动到正确的位置,然后使用以下方法加载弹出框:

(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) 显示弹出框

[annotationPopoverController presentPopoverFromRect:box inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];  

我的直觉是不需要这种解决方法。有没有更简单、更优雅的方法来做到这一点?

谢谢, 马赫什

【问题讨论】:

  • 看看this answer是否有帮助。
  • 谢谢安娜。我正在使用 segues 启动弹出框 - 因此我无法正确定位弹出框。
    如果您使用 segue,我相信我使用的解决方法适用于定位弹出框。话虽如此,我现在正在使用您的答案建议的方法。 self.detailsPopover = [[self storyboard] instantiateViewControllerWithIdentifier:@"identifierName"]; 干杯,马赫什

标签: ipad ios5


【解决方案1】:

谢谢安娜。为重复发布道歉 - Stackoverflow 标记有点问题。

我使用 segues 来启动弹出框 - 因此我无法正确定位弹出框。

如果您使用 segue,我相信我使用的解决方法适合定位弹出框。

话虽如此,我现在正在使用您的答案建议的方法。

我使用

启动弹出框
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];  

【讨论】:

    【解决方案2】:

    我使用表格和动态锚点创建了一个类似的答案。在我的解决方案中,您可以使用 segues 保留情节提要的流程。您将不得不稍微调整答案,但基本相同。

    Is it possible to perform a Popover Segue manually (from dynamic UITableView cell)?

    【讨论】:

      【解决方案3】:
      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
      
              }
              }
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-18
        • 1970-01-01
        • 1970-01-01
        • 2013-08-04
        相关资源
        最近更新 更多