OGeek|极客世界-中国程序员成长平台

标题: ios - 自定义注释 View 未显示在 map 上 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:49
标题: ios - 自定义注释 View 未显示在 map 上

您好,我正在尝试在 map View 中创建自定义注释。在 mapview 中,当用户单击要显示一些文本和按钮的图钉时,我在 map 上有多个图钉制造商,因此尝试创建自定义注释 View ,但它不起作用。

我的代码

#import <MapKit/MapKit.h>
#import <GoogleMaps/GoogleMaps.h>
      @interface myviewcon : UIViewController<MKMapViewDelegate>
      @property (strong, nonatomic) IBOutlet MKMapView *mpview;

    @end

viewdidload 中我的 MKPointAnnotation 代码

for (NSDictionary *dic in [jsonArray1 valueForKey"houses"]) {


      MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init];
      NSString *name=[dic valueForKey"building_name"];

      CLLocationCoordinate2D placeCoord;

      placeCoord.latitude=[[dic objectForKey"lat"] doubleValue];
      placeCoord.longitude=[[dic objectForKey"lng"] doubleValue];



      [annotation setCoordinate:placeCoord];
      [annotation setTitle:name];
      [mpview addAnnotation:annotation];

      }

还有我的自定义注释 View 代码

  - (MKAnnotationView *)mapViewMKMapView *)mV viewForAnnotationid <MKAnnotation>)annotation{

    MKAnnotationView *anview = nil;

    UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    anview.rightCalloutAccessoryView=btnViewVenue;
    anview.enabled = YES;
    anview.canShowCallout = YES;
    anview.multipleTouchEnabled = NO;

    return anview;
  }

当用户单击 map 上的 pin 制造商时,我使用上面的代码制作 customview 我已经用文本和按钮制作了 View ,我已经厌倦了这样但它不起作用我检查了代表正在调用的断点但它不起作用,请告诉如何解决这个问题。

提前致谢。



Best Answer-推荐答案


要自定义您的注释,请使用:

    -(MKAnnotationView *)mapViewMKMapView *)mV viewForAnnotationid <MKAnnotation>)annotation 

这里只添加你需要的 subview

- (void)mapViewMKMapView *)mapView didSelectAnnotationViewMKAnnotationView *)view {

    UIView *test = [[UIView alloc]initWithFrame:CGRectMake(view.frame.origin.x - 12.5, view.frame.origin.y - 45, 50, 50)];
    test.backgroundColor = [UIColor redColor];
    [_mapView addSubview:test];
}

这里只是从 superView 中删除您的自定义 callOutView

- (void)mapViewMKMapView *)mapView didDeselectAnnotationViewMKAnnotationView *)view

关于ios - 自定义注释 View 未显示在 map 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29296493/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4