我设法在Swift中获得了注释引脚的自定义图标,但现在我仍然使用2个不同的图像进行不同的注释.现在,按钮会向地图添加注释.应该有另一个按钮,它还添加了注释,但带有另一个图标.
有没有办法使用reuseId?
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var Map: MKMapView!
@IBAction func btpressed(sender: AnyObject) {
var lat:CLLocationDegrees = 40.748708
var long:CLLocationDegrees = -73.985643
var latDelta:CLLocationDegrees = 0.01
var longDelta:CLLocationDegrees = 0.01
var span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
var location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(lat, long)
var region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
Map.setRegion(region, animated: true)
var information = MKPointAnnotation()
information.coordinate = location
information.title = "Test Title!"
information.subtitle = "Subtitle"
Map.addAnnotation(information)
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if !(annotation is MKPointAnnotation) …Run Code Online (Sandbox Code Playgroud) 我正在开发应用程序,用户通过gps进行本地化,然后询问他是否位于特定位置.为了证实这一点,他会立即向他提出标注泡沫,询问他是否在特定的地方.
由于有很多类似的问题,我能够做自定义标注泡泡:

我的问题:按钮不是"可点击"我的猜测:因为这个自定义标注高于标准标注泡泡,我不得不将它放在负"框架"中,因此无法点击按钮.这是我的didSelectAnnotationView方法
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
if(![view.annotation isKindOfClass:[MKUserLocation class]]) {
CalloutView *calloutView = (CalloutView *)[[[NSBundle mainBundle] loadNibNamed:@"callOutView" owner:self options:nil] objectAtIndex:0];
CGRect calloutViewFrame = calloutView.frame;
calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height);
calloutView.frame = calloutViewFrame;
[calloutView.calloutLabel setText:[(MyLocation*)[view annotation] title]];
[calloutView.btnYes addTarget:self
action:@selector(checkin)
forControlEvents:UIControlEventTouchUpInside];
calloutView.userInteractionEnabled = YES;
view.userInteractionEnabled = YES;
[view addSubview:calloutView];
}
}
Run Code Online (Sandbox Code Playgroud)
CalloutView只是简单的类,有2个属性(标签显示地方名称和按钮)和xib.
我一直在做这个自定义标注泡泡几天.我尝试使用"异步解决方案" 解决方案,但我无法添加任何其他类型的按钮然后披露按钮.
我的下一次尝试是找到比异步解决方案更容易的东西并将其修改为我的用途.多数民众赞成我如何找到tochi的自定义标注.

基于他的工作,我能够自定义他的泡泡并更改我的自定义按钮的信息按钮.然而,我的问题仍然存在.为了将我的自定义标注视图放在引脚顶部,我不得不给它负帧,所以我的按钮只能在底部5个像素中"可点击".看来,我必须深入挖掘ios默认的标注气泡,将其子类化并在那里更改标注框架.但我现在真的很无望.
如果你们能告诉我正确的方法,或者给我建议,我会很高兴的.

我需要在MKMapView上创建上面的Annotation视图.我能够创建自定义注释视图,但在点击注释时,视图需要打开带有大文本的图像,我无法创建那个.请提供一些链接或方法来完成这项任务.
我是objective-c中的mapkit新手.我可以在mapview中添加自定义注释.
我需要放置自定义标注视图,如下图所示
.
但我没有得到如何设计这样的标注视图.
我知道我需要在视图中为注释方法添加callout.
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.image = [UIImage imageNamed:@"blue_without_pin.png"];
annotationView.annotation = annotation;
return annotationView;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在地图中的图钉顶部显示自定义呼叫。我需要在图钉顶部显示带有一些文字的图像作为我的呼唤。我编写的代码产生以下输出。
但是,我想要的输出如下所示:
我怎样才能达到我想要的输出?请注意,气泡是必须使用的图像资产,我知道如何使用 CAShapeLayer 绘制气泡,但这并不能完成我想要的。这是到目前为止的代码。
// methods for Custom annotations
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView = MKAnnotationView(annotation: pin, reuseIdentifier: "UserLocation")
annotationView.image = UIImage(named: "marker")
annotationView.canShowCallout = true
configureDetailView(annotationView: annotationView)
return annotationView
}
func configureDetailView(annotationView: MKAnnotationView) {
let width = 300
let height = 200
let calloutView = UIView()
calloutView.translatesAutoresizingMaskIntoConstraints = false
let views = ["calloutView": calloutView]
calloutView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[calloutView(300)]", options: [], metrics: nil, views: views))
calloutView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[calloutView(200)]", options: [], metrics: nil, views: views))
let …Run Code Online (Sandbox Code Playgroud)