7
votes

It works great on iOS 7 but UIImageView's position shifts on iO8 like images below. Also rightCalloutAccessoryView position shifts top-right corner.

Can anybody help?

Cheers.

In iOS 7

iOS 7

In iOS 8

iOS8

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

if(![view.annotation isKindOfClass:[MKUserLocation class]]) {

    UBAnnotation *selectedAnnotation = view.annotation;

    NSURL * imageUrlAtIndex = [NSURL URLWithString:[[self.objects objectAtIndex:selectedAnnotation.idx] ad_thumbImageUrl]];


    UIImageView * leftCalloutView = [[UIImageView alloc] initWithFrame:CGRectMake(2, 2, 40, 40)];
    [leftCalloutView setImageWithURL:imageUrlAtIndex];
    leftCalloutView.layer.masksToBounds = YES;
    leftCalloutView.layer.cornerRadius = 6;

    view.leftCalloutAccessoryView = leftCalloutView;

}

}

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

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];

if ([annotation isKindOfClass:[MKUserLocation class]]) {
    return nil;
} else {
    annView.image = [UIImage imageNamed:@"pin"];

    annView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    annView.rightCalloutAccessoryView.tintColor = [UBColor ubGreenColor];
    annView.animatesDrop= NO;
    annView.canShowCallout = YES;

}

return annView;

}

3

3 Answers

6
votes

I solved it!

It's all about titleLabel's string length. If the string length over 20-25 character, left and right accessory view shifts up.

First, I trimmed the string that shown on title label or subtitle label. After, concatenate "..." as string at the end of the string.

Solution is a little bit hack, but it works like charm.

0
votes

I made fix like this. Needs to polish the code, but for me it works.

- (UIView*)rightCalloutAccessoryView {
    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    return [self parentViewForView:rightButton];
}

- (UIView*)parentViewForView:(UIView*)view {
#ifdef __IPHONE_8_0
    CGRect rr = view.frame;
    rr.origin.x = 2.0f;
    rr.origin.y = (64.0f - rr.size.height ) / 2.0f;
    view.frame = rr;
    UIView *result = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rr.size.width + 4.0f, 64.0f)];
    [result addSubview:view];
    return result;
#else
    return view;
#endif
}
0
votes

If you want to customize the leftCalloutAccessoryView be implemented an customizedView that you have to refine the width been under 225.0f ( the better setup is 220.0f ) on iPhone 4, 4S, 5, 5+.

for example :

UIView *_customContentView    = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 225.0f, 38.0f)];
view.leftCalloutAccessoryView = _customContentView;

That's my solved experience.