2012-05-16 105 views
0

我已經實現了tapOnMarker選擇器,並創建了自定義annotationView。並且它是顯示註釋的視圖,但是當我點擊精確的時候,然後註釋視圖抽象出當前精確到小於的精確點並且精確到最大值顯示在註釋視圖上,這裏是我的實現代碼。 如何在RMMapview中顯示自定義註釋視圖,點擊精確位置?

- (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

請添加一些格式化爲您的問題。目前它是無法讀取的。 – 0x90

+0

我需要抽象所有視點覆蓋到viewAnnotation區域? – user1023772

回答

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]; 
} 
相關問題