2011-08-22 4 views
0

이지도보기 위임 방법을 확대 :원하지 않는 나는 (내가 생각하는)에 문제가있어 다시 선택지도 핀

내가 핀을 선택한 후
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 

, 그것은 콜 아웃을 보여줍니다.

지도를 이동하면 핀과 콜 아웃이 보이지 않거나 (두 개 또는 세 개의 스크린이 멀리 떨어져 있음) 다른 영역을 확대 한 다음 선택한 핀으로 확대/축소합니다.

핀이 메모리를 벗어나서 다시 만들어 졌기 때문에이 작업을 수행하고있는 것 같습니다. 다시 만들어지면 선택되고 뷰가 확대됩니다.

줌을 사용하지 않으려면 어떻게해야합니까?

아래의 Anna K는이 방법을 요구했습니다. 또한 viewForAnnotation을 붙여 넣었습니다.

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view { 

    if ([view.annotation isKindOfClass:[MKUserLocation class]]) { 
     // 
     NSLog(@"selected user loc"); 

    } else 
    { 

     selectedAnnotation = view.annotation; 

     if (self.calloutAnnotation == nil) { 
      self.calloutAnnotation = [[CalloutMapAnnotation alloc] initWithLatitude:view.annotation.coordinate.latitude 
                     andLongitude:view.annotation.coordinate.longitude]; 
     } else { 
      self.calloutAnnotation.latitude = view.annotation.coordinate.latitude; 
      self.calloutAnnotation.longitude = view.annotation.coordinate.longitude; 
     } 

     // this doesn't allow user to click away from selected pin to another 
     // [self.mapView addAnnotation:self.calloutAnnotation]; 
     // this fixes it 
     [self.mapView performSelector:@selector(addAnnotation:) withObject:self.calloutAnnotation afterDelay:0.005]; 

     self.selectedAnnotationView = view; 
     BasicMapAnnotationView *tempAnnView = (BasicMapAnnotationView *)view; 
     selectedPin = tempAnnView.tag; 


    } 

} 





- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 

    originalRegion = self.mapView.region; 
    if (annotation == self.calloutAnnotation) { 

     NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"storeID == %@", [NSNumber numberWithInt:selectedPin]]; 
     NSMutableArray* mutableFetchResults = [CoreDataHelper searchObjectsInContext:@"Store" :searchPredicate :@"storeName" :YES :self.managedObjectContext]; 

     if ([mutableFetchResults count] > 0) 
     { 
      Singleton *singleton = [Singleton sharedSingleton]; 
      Store *tempStore = (Store*)[mutableFetchResults objectAtIndex:0]; 
      if (tempStore.storeIsPicked == [NSNumber numberWithBool:YES]) { 
       singleton.isPicked = YES; 
      } else 
      { 
       singleton.isPicked = NO; 
      } 

     } 


      AccessorizedCalloutMapAnnotationView *calloutMapAnnotationView = [[[AccessorizedCalloutMapAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"CalloutAnnotation"] autorelease]; 
    calloutMapAnnotationView.contentHeight = 40.0; 


      if ([mutableFetchResults count] > 0) 
      { 

       Store *store = (Store*)[mutableFetchResults objectAtIndex:0]; 

       UILabel *shopName = [[UILabel alloc] initWithFrame:CGRectMake(36, -3, 250, 29)]; 
       shopName.font = [UIFont boldSystemFontOfSize:14.0]; 
       shopName.text = store.storeName; 
       shopName.backgroundColor= [UIColor clearColor]; 

       UILabel *addressName = [[UILabel alloc] initWithFrame:CGRectMake(36, 13, 250, 29)]; 
       addressName.font = [UIFont systemFontOfSize:9.0]; 
       addressName.textColor = [UIColor lightGrayColor]; 
       addressName.text = store.storeAddress; 
       addressName.backgroundColor= [UIColor clearColor]; 

       [calloutMapAnnotationView.contentView addSubview:shopName]; 
       [calloutMapAnnotationView.contentView addSubview:addressName]; 

       calloutMapAnnotationView.parentAnnotationView = self.selectedAnnotationView; 

       [shopName release]; 
       [addressName release]; 
       calloutMapAnnotationView.mapView = self.mapView; 
       return calloutMapAnnotationView; 
      } else 
      { 
       NSLog(@"returning nil .. no stores"); 
       return nil; 
      } 



    } 

    else 
    { 

     if ([annotation isKindOfClass:[MKUserLocation class]]) 
     { 
      // do something with blue dot? 

     } 
     else 
     { 

      BasicMapAnnotationView *annotationView = [[[BasicMapAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomAnnotation"] autorelease]; 
      BasicMapAnnotation *tempAn = (BasicMapAnnotation *)annotation; 



      if ([annotation isKindOfClass:[BasicMapAnnotation class]]) 
       { 
       NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"storeID == %@", [NSNumber numberWithInt:tempAn.mapTag]]; 

       NSMutableArray* mutableFetchResults = [CoreDataHelper searchObjectsInContext:@"Store" :searchPredicate :@"storeName" :YES :self.managedObjectContext]; 

       if ([mutableFetchResults count]>0) 
       { 
        Store *store = [mutableFetchResults objectAtIndex:0]; 

        BOOL isPicked = [store.storeIsPicked boolValue]; 
        if (isPicked) 
        { 
         annotationView.image = [UIImage imageNamed:@"pinPicked.png"]; 


        } else 
        { 
         annotationView.image = [UIImage imageNamed:@"pinOff.png"]; 


        } 
        annotationView.centerOffset = CGPointMake(-8, -9); 
        annotationView.canShowCallout = NO; 
        annotationView.tag = tempAn.mapTag; 
        return annotationView; 
       } 
       } 
     } 
    } 


    return nil; 
} 
+0

지도보기는 지역이나 중심을 자동으로 변경하지 않습니다. 코드가지도의 영역, visibleMapRect 또는 centerCoordinate를 변경하는 모든 곳을 찾아서 어떻게 든 호출되는지 확인합니다. 핀이 선택되었을 때 실행되는 코드가 있습니까? – Anna

+0

viewForAnnotation으로 다시 만들면 선택되기 때문에 지역을 변경한다고 생각합니다. 내가 틀렸을 수도있다. 그것은 또한 내가 dequeueReusableAnnotationViewWithIdentifier를 사용하지 않을 수 있지만 단순히 그것을 만들 수 있습니다 ..? – cannyboy

+0

코드가지도의 지역, visibleMapRect 또는 centerCoordinate를 변경하지 않습니다. viewForAnnotation 및 didSelectAnnotationView에 코드를 게시하십시오 (구현 된 경우). – Anna

답변

0

나는이 문제가 과거에 있었고 문제는지도 영역이 핀 위치에 의해 정의된다는 것입니다. viewDidLoad 메서드의 mapView setRegion 코드를 원하는 위치로 변경하고 필요에 따라 사용자 위치 또는 원하는대로 업데이트해야합니다.

- (void)viewDidLoad{ 
[super viewDidLoad]; 

// define span for map: how much area will be shown 
MKCoordinateSpan span; 
span.latitudeDelta = 0.002; 
span.longitudeDelta = 0.002; 

// define starting point for map 
CLLocationCoordinate2D start; 
start.latitude = 42.36873056998856; //Change to what you desire for starting point 
start.longitude = -71.11504912376404; //Could also be set to user or pin Location if desired 

// create region, consisting of span and location 
MKCoordinateRegion region; 
region.span = span; 
region.center = start; 

// move the map to our location 
[self.mapView setRegion:region animated:YES]; 
} 
관련 문제