So the centerOffset property of MKAnnotation does not seem to work on iOS7 for working with custom annotation images... Below are images taken in iOS6 (working) and in iOS7 (not working).
Do you guys know what's causing this issue? Is there any fix for this?
It's not that the centerOffset value is incorrent in iOS7, it's that the offset does not change whatever it receives as a value.
EDIT: Sample code:
- (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 a few irrelevant properties.
EDIT:
As @Anna Karenina made me realize, I was using MKPinAnnotationView instead of MKAnnotationView. Apparently MKPinAnnotation has a baked in centerOffset, that is the reason behind the strange behaviour.
THE ORIGINAL ANSWER:
For anyone having the same issue, this seems to be a bug in iOS7.
Workaround:
Subclass MKAnnotationView
and overwrite the setter method
for the centerOffset
property.
Nothing new in the .h header file, and this is how the .m implementation file should look like:
#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 on the top!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With