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;
}
지도보기는 지역이나 중심을 자동으로 변경하지 않습니다. 코드가지도의 영역, visibleMapRect 또는 centerCoordinate를 변경하는 모든 곳을 찾아서 어떻게 든 호출되는지 확인합니다. 핀이 선택되었을 때 실행되는 코드가 있습니까? – Anna
viewForAnnotation으로 다시 만들면 선택되기 때문에 지역을 변경한다고 생각합니다. 내가 틀렸을 수도있다. 그것은 또한 내가 dequeueReusableAnnotationViewWithIdentifier를 사용하지 않을 수 있지만 단순히 그것을 만들 수 있습니다 ..? – cannyboy
코드가지도의 지역, visibleMapRect 또는 centerCoordinate를 변경하지 않습니다. viewForAnnotation 및 didSelectAnnotationView에 코드를 게시하십시오 (구현 된 경우). – Anna