2015-04-05 111 views
0

我有一個圖像,我想要在用戶位置的右側,我該如何去做呢?有沒有辦法獲得用戶位置的x和y座標,然後獲取圖像的x和y以確保其始終位於右側?找到用戶位置的x和y座標

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{ 

    MKCoordinateRegion region; 
    region.center = worldView.userLocation.coordinate; 
    MKCoordinateSpan span; 
    span.latitudeDelta = 5; 
    span.longitudeDelta = 5; 
    region.span = span; 
    [worldView setRegion:region animated:YES]; 

    UIImage *commentBox = [UIImage imageNamed:@"comment-box"]; 
    UIImageView *commentBoxImageView = [[UIImageView alloc] initWithImage:commentBox]; 
    [self.view addSubview:commentBoxImageView]; 

} 

回答

1

最簡單的解決方案是使該圖像成爲註釋視圖。這是屬於地圖視圖的東西 - 地圖將繪製註記視圖,並在地圖滾動或區域更改時將其保留在其座標處。現在你所要做的就是繼續觀察用戶的座標並確保註釋位於該座標的東邊。