我已经实现了tapOnMarker选择器,并创建了自定义的annotationView。并且它显示了annotationView,但是当我点击精确定位时,则annotationView抽象精确计数小于当前精确点的精确点,并且精确定位数显示在annotationView上,这是我的实现代码。
- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map
{
frame = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redbox.png"]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(0, 0,0, 0);
[button setBackgroundImage:[UIImage imageNamed:@"pinMarker.png"] forState:UIControlStateNormal];
button.enabled = YES;
button.userInteractionEnabled = YES;
[button addTarget:self action:@selector(markerLabelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[marker setLabel:frame];
}
- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map
{
frame = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redbox.png"]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(0, 0,0, 0);
[button setBackgroundImage:[UIImage imageNamed:@"pinMarker.png"] forState:UIControlStateNormal];
button.enabled = YES;
button.userInteractionEnabled = YES;
[button addTarget:self action:@selector(markerLabelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[marker setLabel:frame];
}
答案 0 :(得分:1)
加载标记时,请执行以下步骤:
RMMarker *marker = [[RMMarker alloc]initWithUIImage:img anchorPoint:CGPointMake(0.5, 1.0)];
[marker setText:@"hello" forMarker: marker];
[marker hideLabel];
- (void) setText: (NSString*) text forMarker: (RMMarker*) marker
{
CGSize textSize = [text sizeWithFont: [RMMarker defaultFont]];
CGPoint position = CGPointMake( -(textSize.width/2 - marker.bounds.size.width/2), 0 );
[marker changeLabelUsingText: text position: position font: [UIFont systemFontOfSize: 15.0]foregroundColor: [UIColor whiteColor] backgroundColor: [UIColor blackColor]];
}
无论何时单击标记,都会调用这些方法并显示标记:
- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map
{
NSArray* markers = [self.markerManager markers];
for(RMMarker* m in markers) {
if ([m class] == [RMMarker class])
[m hideLabel];
}
[marker showLabel];
}