2014-03-28 28 views
0

我想創建不帶標註的自定義MKAnnotationView(帶圖像),但在觸摸後可擴展。以下是我心目中:自定義MKAnnotationView無需標註即可展開

1)首先MKAnnotation看起來是這樣的:

enter image description here

2)然後在其上點擊此應擴大,看起來像這樣經過:

enter image description here

我已經開始定製MKAnnotationView並且有一個類:

@interface CustomPinAnnotation : NSObject <MKAnnotation>

類有方法:

-(MKAnnotationView*)annotationView { 
    MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:self reuseIdentifier:@"AnnotationIdentifier"]; 
    annotationView.enabled = YES; 
    annotationView.image = [[UIImage imageNamed:@"star"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 

    return annotationView; 
} 

什麼我嘗試做的是設置一個customView作爲一個子視圖到MKAnnotationView,但是當我不設置圖像也不會響應(此在我考慮這個問題之後,我覺得這很合乎邏輯),但是感覺我在這裏做的事情非常討厭,應該是一種以某種方式覆蓋MKAnnotationView的方法。

回答

1
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
    { 
      enemyAnnotationView.image = [UIImage imageNamed:@"firstImage.png"]; 
    } 

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 
    { 
      enemyAnnotationView.image = [UIImage imageNamed:@"SecondImage.png"]; 
    } 

嘗試這樣的第一種方法是查看了註解看來,時間你的第一個形象會,

第二種方法將運行時用戶選擇註釋

+0

哦,容易和完美!我知道我正在過度引導它:)謝謝! – Kuba