IOS7: MKnnotation centerOffset?

Thus, the centerOffset property for MKAnnotation does not seem to work on iOS7 to work with custom annotation images ... The following are shots taken in iOS6 (working) and in iOS7 (not working).

Do you guys know what causes this problem? Is there any fix for this?

Not that the centerOffset value was set in iOS7, it means that the offset does not change what it gets as the value.

iOS6iOS7

EDIT : Code Example:

- (void)viewDidLoad { [super viewDidLoad]; MapAnnotation *ann = [[MapAnnotation alloc] initWithName:@"Some annotation" latitude:46.910068 longitude:17.881984 tag:1 type:MAP_ANNOTATION_TYPE_REQUEST]; self.mapView.delegate = self; [self.mapView addAnnotation:ann]; MKCircle *circle = [MKCircle circleWithCenterCoordinate:CLLocationCoordinate2DMake(46.910068, 17.881984) radius:10]; [self.mapView addOverlay:circle]; } - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay { if ([overlay isKindOfClass:[MKCircle class]]) { MKCircleView *cv = [[MKCircleView alloc] initWithCircle:overlay]; cv.fillColor = [UIColor colorWithRed:247/255.f green:85/255.f blue:86/255.f alpha:0.2]; cv.lineWidth = 1; cv.strokeColor = [UIColor colorWithRed:247/255.f green:85/255.f blue:86/255.f alpha:1.0]; return cv; } return nil; } - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { //User location if ([annotation isKindOfClass:[MKUserLocation class]]) return nil; //Annotations MKPinAnnotationView *pinAnnotation = nil; if(annotation != self.mapView.userLocation) { // Dequeue the pin static NSString *defaultPinID = @"myPin"; pinAnnotation = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; if ( pinAnnotation == nil ) pinAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID]; pinAnnotation.image = [UIImage imageNamed:@"subscription-map-icon"]; pinAnnotation.centerOffset = CGPointMake(0, -20); } return pinAnnotation; } 

MapAnnotation is a simple annotation class that has several irrelevant properties.

+6
source share
1 answer

EDIT:

As @Anna Karenina made me realize, I used MKPinAnnotationView instead of MKAnnotationView . Apparently, MKPinAnnotation has baked in centerOffset, which is the reason for the strange behavior.

ORIGINAL RESPONSE:

For those who have the same problem, this seems like a bug in iOS7.

Workaround:

Subclass MKAnnotationView and overwrite the setter method for the centerOffset property.

Nothing new in the .h header file, and the .m implementation file should look like this:

 #import "MyAnnotationView.h" @implementation MyAnnotationView @synthesize centerOffset = _centerOffset; -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } - (void)setCenterOffset:(CGPoint)centerOffset { _centerOffset = centerOffset; } @end 

Don't miss the @synthesize part @synthesize top!

+21
source

Source: https://habr.com/ru/post/956866/


All Articles