【问题标题】:Add padding to edges of MKMapView in Xamarin C#在 Xamarin C# 中向 MKMapView 的边缘添加填充
【发布时间】:2014-03-16 20:04:14
【问题描述】:

我有一个显示两点之间路线的 MKMapView。这些点可以改变,所以我希望 MapView 放大以显示完整的路线。我用这段代码修复了它:

_map.SetVisibleMapRect(_routeOverlay.BoundingMapRect, true);

现在我想要在边缘周围进行一些填充,因为路线现在非常靠近屏幕边缘。如何向 MapView 添加填充?

附言。我用这段代码让它在本机 iOS Xcode 中工作,但我无法让它与 Xamarin 和 C# 一起工作:

[self.mapView2 setVisibleMapRect:[_routeOverlay boundingMapRect] edgePadding:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0) animated:YES];

【问题讨论】:

    标签: c# ios xamarin padding


    【解决方案1】:

    在几次错误之后,我终于修复了它。我只需要像这样将 UIEdgeInsets 添加到我的 SetVisibleMapRect() 中:

    _map.SetVisibleMapRect (_routeOverlay.BoundingMapRect, new UIEdgeInsets(20, 20, 20, 20), true);
    

    感谢@Jason 为我指明了正确的方向。

    【讨论】:

      【解决方案2】:

      SetVisibleMapRect() 有一个重载:

      public virtual void SetVisibleMapRect (MKMapRect mapRect, MonoTouch.UIKit.UIEdgeInsets edgePadding, bool animate)
      

      【讨论】:

      • 这似乎是对的,但我不知道如何实现它。我的代码在公共方法中,我应该在哪里重载?
      • 你把它放在你现有的 SetVisibleRect() 方法调用的地方。只需使用带有三个参数的版本,而不是带有 2 个参数的版本。
      猜你喜欢
      • 2015-08-14
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 2015-01-31
      • 2014-11-06
      • 1970-01-01
      相关资源
      最近更新 更多