本文介绍了添加图片到我的注释的左边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我已经创建了注解,完美出现在我的地图,但我不知道如何实现leftCalloutAccessoryView显示图像的任何指导,将是非常美联社preciated

MapViewAnnotation.h

 #进口<基金会/ Foundation.h>
#进口< MapKit / MapKit.h>@interface MapViewAnnotation:NSObject的< MKAnnotation>@属性(非原子,分配)CLLocationCoordinate2D协调;
@属性(非原子,副本)的NSString *称号;
@属性(非原子,副本)的NSString *字幕;@结束

MapViewAnnotation.m

 #进口MapViewAnnotation.h@implementation MapViewAnnotation
@synthesize协调,标题,副标题;@结束

GroundsViewController.h

 #进口<的UIKit / UIKit.h>
#进口< MapKit / MapKit.h>
@interface GroundsViewController:的UIViewController< MKMapViewDelegate>
{
    *的MKMapView图形页面;
}@property(强,非原子)IBOutlet中UISegmentedControl *段; - (IBAction为)changeSeg:(ID)发送;
@结束

GroundsViewController.m

 #进口GroundsViewController.h
#进口MapViewAnnotation.h@interface GroundsViewController()
@结束//中心北爱尔兰#定义Northern_Ireland_Latitude 54.629338;
#定义Northern_Ireland_Longitude -6.668701;//跨度#定义The_Span 2.00f;
// premiership#定义Ballymena_Latitude 54.870105;
#定义Ballymena_Longitude -6.265076;
//锦标赛1#定义Ards_Latitude 54.651629;
#定义Ards_Longitude -5.684478;//锦标赛2#定义Annagh_Latitude 54.411372;
#定义Annagh_Longitude -6.440355;
@implementation GroundsViewController@synthesize段; - (IBAction为)changeSeg:(ID)发送{
    如果(segment.selectedSegmentIndex == 0){
        mapView.mapType = MKMapTypeStandard;
    }    如果(segment.selectedSegmentIndex == 1){
        mapView.mapType = MKMapTypeSatellite;
    }    如果(segment.selectedSegmentIndex == 2){
        mapView.mapType = MKMapTypeHybrid;
    }}//当视图加载
- (无效)viewDidLoad中
{
    图形页面= [[的MKMapView页头] initWithFrame:方法self.view.bounds];
    [self.view insertSubview:图形页面atIndex:0];    //创建区域    MKCoordinateRegion myRegion;    // 中央    CLLocationCoordinate2D中心;
    center.latitude = Northern_Ireland_Latitude;
    center.longitude = Northern_Ireland_Longitude;    //创建跨度    MKCoordinateSpan跨度;
    span.latitudeDelta = The_Span;
    span.longitudeDelta = The_Span;    myRegion.center =中心;
    myRegion.span =跨度;    //设置我们的地图视图    [图形页面setRegion:myRegion动画:是];
    NSMutableArray里*地点= [[NSMutableArray里的alloc]初始化];
    CLLocationCoordinate2D位置;
    MapViewAnnotation * myAnn;    // premiership    //引脚显示巴利米纳联足球俱乐部
    myAnn = [[MapViewAnnotation的alloc]初始化];
    location.latitude = Ballymena_Latitude;
    location.longitude = Ballymena_Longitude;
    myAnn.coordinate =位置;
    myAnn.title = @巴利米纳联足球俱乐部;
    myAnn.subtitle = @的展览场地;
    [地点ADDOBJECT:myAnn];
    //锦标赛1    //引脚显示阿兹F.C.
    myAnn = [[MapViewAnnotation的alloc]初始化];
    location.latitude = Ards_Latitude;
    location.longitude = Ards_Longitude;
    myAnn.coordinate =位置;
    myAnn.title = @阿兹足球俱乐部;
    myAnn.subtitle = @Clandeboye园;
    [地点ADDOBJECT:myAnn];
    //锦标赛2    //引脚显示安纳联足球俱乐部
    myAnn = [[MapViewAnnotation的alloc]初始化];
    location.latitude = Annagh_Latitude;
    location.longitude = Annagh_Longitude;
    myAnn.coordinate =位置;
    myAnn.title = @安纳联足球俱乐部;
    myAnn.subtitle = @Tandragee之路;
    [地点ADDOBJECT:myAnn];
    [个体经营>的MapView addAnnotations:地点];} - (空)didReceiveMemoryWarning
{
    [超级didReceiveMemoryWarning];
    可以重新创建任何资源的处置//。
}@结束


解决方案

   - (MKAnnotationView *)的MapView:(的MKMapView *)的MapView viewForAnnotation:(ID< MKAnnotation>)注释{静态的NSString *标识符= @MyLocation
如果([注解isKindOfClass:[标类]){    MKPinAnnotationView * annotationView =
    (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:符];    如果(annotationView ==无){
        annotationView = [[MKPinAnnotationView页头]
                          initWithAnnotation:注释
                          reuseIdentifier:符];
    }其他{
        annotationView.annotation =注释;
    }    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;
*的UIImageView = imvLeft [[UIImageView的页头]初始化];
//设置图片
    [annotationView setLeftCalloutAccessoryView:imvLeft];    返回annotationView;
}回零;

}

Hi i have created annotations that show up perfectly on my map but i am not sure how to implement the leftCalloutAccessoryView to show images any guidance would be much appreciated

MapViewAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapViewAnnotation : NSObject <MKAnnotation>

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;

@end

MapViewAnnotation.m

#import "MapViewAnnotation.h"

@implementation MapViewAnnotation
@synthesize coordinate, title, subtitle;

@end

GroundsViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>


@interface GroundsViewController : UIViewController <MKMapViewDelegate>
{
    MKMapView *mapView;
}

@property (strong, nonatomic) IBOutlet UISegmentedControl *segment;

- (IBAction)changeSeg:(id)sender;
@end

GroundsViewController.m

#import "GroundsViewController.h"
#import "MapViewAnnotation.h"

@interface GroundsViewController ()


@end

// Centre in on Northern Ireland

#define Northern_Ireland_Latitude 54.629338;
#define Northern_Ireland_Longitude -6.668701;

//Span

#define The_Span 2.00f;


// Premiership

#define Ballymena_Latitude 54.870105;
#define Ballymena_Longitude -6.265076;


// Championship 1

#define Ards_Latitude 54.651629;
#define Ards_Longitude -5.684478;

// Championship 2

#define Annagh_Latitude 54.411372;
#define Annagh_Longitude -6.440355;


@implementation GroundsViewController

@synthesize segment;

- (IBAction)changeSeg:(id)sender {
    if (segment.selectedSegmentIndex == 0) {
        mapView.mapType = MKMapTypeStandard;
    }

    if (segment.selectedSegmentIndex == 1) {
        mapView.mapType = MKMapTypeSatellite;
    }

    if (segment.selectedSegmentIndex == 2) {
        mapView.mapType = MKMapTypeHybrid;
    }

}

// When the view loads
- (void)viewDidLoad
{
    mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
    [self.view insertSubview:mapView atIndex:0];

    // Create the region

    MKCoordinateRegion myRegion;

    // Center

    CLLocationCoordinate2D center;
    center.latitude = Northern_Ireland_Latitude;
    center.longitude = Northern_Ireland_Longitude;

    // Create the Span

    MKCoordinateSpan span;
    span.latitudeDelta = The_Span;
    span.longitudeDelta = The_Span;

    myRegion.center = center;
    myRegion.span = span;

    // Set our map view

    [mapView setRegion:myRegion animated:YES];


    NSMutableArray *locations = [[NSMutableArray alloc] init];
    CLLocationCoordinate2D location;
    MapViewAnnotation *myAnn;

    //Premiership

    // Pin to show Ballymena United F.C.
    myAnn = [[MapViewAnnotation alloc] init];
    location.latitude = Ballymena_Latitude;
    location.longitude = Ballymena_Longitude;
    myAnn.coordinate = location;
    myAnn.title = @"Ballymena United F.C.";
    myAnn.subtitle = @"The Showgrounds";
    [locations addObject:myAnn];


    // Championship 1

    // Pin to show Ards F.C.
    myAnn = [[MapViewAnnotation alloc] init];
    location.latitude = Ards_Latitude;
    location.longitude = Ards_Longitude;
    myAnn.coordinate = location;
    myAnn.title = @"Ards F.C.";
    myAnn.subtitle = @"Clandeboye Park";
    [locations addObject:myAnn];


    // Championship 2

    // Pin to show Annagh United F.C.
    myAnn = [[MapViewAnnotation alloc] init];
    location.latitude = Annagh_Latitude;
    location.longitude = Annagh_Longitude;
    myAnn.coordinate = location;
    myAnn.title = @"Annagh United F.C.";
    myAnn.subtitle = @"Tandragee Road";
    [locations addObject:myAnn];


    [self->mapView addAnnotations:locations];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
解决方案
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[PlaceMark class]]) {

    MKPinAnnotationView *annotationView = 
    (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    if (annotationView == nil) {
        annotationView = [[MKPinAnnotationView alloc] 
                          initWithAnnotation:annotation 
                          reuseIdentifier:identifier];
    } else {
        annotationView.annotation = annotation;
    }

    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;


UIImageView *imvLeft = [[UIImageView alloc] init];
//Set Image
    [annotationView setLeftCalloutAccessoryView:imvLeft];

    return annotationView;
}

return nil; 

}

这篇关于添加图片到我的注释的左边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 11:58