简体   繁体   English

iOS-创建自定义MKAnnotation标注的问题

[英]iOS - Issue Creating Custom MKAnnotation Callout

Im having some issues styling my MKAnnotation callout bubble. 我在设置MKAnnotation标注气泡时遇到了一些问题。 Originally I had a standard callout that consisted of just a title, subtitle and leftCalloutAccessoryView . 最初,我有一个标准的标注,仅包含标题,副标题和leftCalloutAccessoryView This created the following callout: 这创建了以下标注:

在此处输入图片说明

This worked fine until it was decided that the subtitle should also contain a series of five images that show the business's average ratting among user reviews. 直到确定该字幕还应包含一系列由五张图像组成的图像,这些图像显示该企业在用户评论中的平均评分后,此方法才能正常工作。 This was done by creating a separate view and passing it as the detailCalloutAccessoryView . 这是通过创建一个单独的视图并将其作为detailCalloutAccessoryView传递来detailCalloutAccessoryView This produced the following callout bubble: 这产生了以下标注气泡:

在此处输入图片说明

For some reason when the view is passed to the detailCalloutAccessoryView the callout view is given a weird border around all UI components that create unwanted whitespace around the leftCalloutAccessoryView and between the title and subtitle. 出于某种原因,当视图传递到detailCalloutAccessoryView ,会在所有UI组件周围为标注视图提供一个奇怪的边框,这些组件会在leftCalloutAccessoryView周围以及标题和副标题之间创建不必要的空格。 How can I remove this white space? 如何删除空白? I want the business's average ratting inside the subtitle and proper spacing between the title and detailCalloutAccessoryView . 我想要企业在字幕内的平均detailCalloutAccessoryView以及标题和detailCalloutAccessoryView之间的适当间距。 How can this be achieved? 如何做到这一点? Is it possible to do so without creating the callout from scratch? 是否可以这样做而无需从头开始创建callout

Without code, it is hard to give a detailed answer. 没有代码,很难给出详细的答案。
But I found a hint that may solve your problem in this post : 但是我在这篇文章中发现了一个可能解决您问题的提示:
Apparently, MapKit sets translatesAutoresizingMaskIntoConstraints to false , when you set a view to detailCalloutAccessoryView . 显然,MapKit套translatesAutoresizingMaskIntoConstraintsfalse ,当你设置一个视图detailCalloutAccessoryView
This means that you have to set auto layout constraints by your own. 这意味着您必须自己设置自动布局约束。

I suggest you create one custom pin representing the Bubble (BubblePin), and each time the user selects one regular pin, you add the BubblePin at the same position of the last selected regular pin. 我建议您创建一个代表Bubble(BubblePin)的自定义引脚,并且每次用户选择一个常规引脚时,都将BubblePin添加到最后选择的常规引脚的相同位置。 So adding one additional pin and switching its position according to the user selection will solve the problem, just make sure to add the BubblePin some offset so it won't be right on top of the regular one. 因此,添加一个额外的引脚并根据用户选择切换其位置将解决该问题,只需确保将BubblePin添加一些偏移量,以使其不会位于常规引脚的顶部即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM