c# - Xamarin Forms IOS - MKUserTrackingButton 位置

标签 c# ios xamarin xamarin.forms xamarin.ios

目前,我的 Xamarin Forms 中有一个自定义 map 渲染器,它为每个平台使用 native map 渲染器。

对于 iOS,我正在尝试添加一个跟踪按钮以返回当前位置。

我有创建按钮的代码:

   var button = MKUserTrackingButton.FromMapView(Map);
            button.Layer.BackgroundColor = UIColor.White.CGColor;
            button.Layer.BorderColor = UIColor.FromRGB(211, 211, 211).CGColor;
            button.Layer.BorderWidth = 1;
            button.Layer.CornerRadius = 5;
            button.TranslatesAutoresizingMaskIntoConstraints = false;
            Map.AddSubview(button);

但我需要将其移至右下角(见下图)

enter image description here

所以我只需要一行代码来移动 map View 中的按钮:)

最佳答案

如果您想使用 Frame 来更改 Control 的位置。您应该删除 button.TranslatesAutoresizingMaskIntoConstraints = false;。此代码将禁用框架,并使用自动布局来放置控件。

您也可以尝试使用自动布局:

button.TopAnchor.ConstraintEqualTo(Map.TopAnchor, 100).Active = true;
button.LeadingAnchor.ConstraintEqualTo(Map.LeadingAnchor, 100).Active = true;
button.WidthAnchor.ConstraintEqualTo(52).Active = true;
button.HeightAnchor.ConstraintEqualTo(44).Active = true;

关于c# - Xamarin Forms IOS - MKUserTrackingButton 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49337958/

相关文章:

c# - 将 CheckBoxList 绑定(bind)到通用列表

c# - 使用绘制事件移动对象

c# - 当用户拥有先前有效的 cookie 时,如何删除对网站的访问?

c# regex 和 [] expression ,为什么 [+*/-] 无法解析?

iOS 在新的 WebView 中打开 WebView href

iOS UITextView 设置文本 EXC_BAD_ACCESS

ios - AppStore - 未找到构建版本

c# - Xamarin slider 自定义渲染器 DragCompleted 事件

ios - 尝试 JIT 编译方法 '(wrapper delegate-invoke) - System.Net.HttpWebRequest

ios - AVPlayerLayer 实例化慢