I have trouble with MKAnnotationView Frame. Before asking I want to clarify some things.
First:
I have a MKMapView
and some custom annotation:
It looks ok.
Second I draw a Line via MKPolylineView
between user's location and this custom annotation:
Looks pretty good
Third, Then I tried to change default annotation image by my own custom:
Right here we have wrong result, coz annotation not not connected with line
Forth, Okey I tried to change position of this image:
I just added to MKAnnotationView
a new UIView
with my UIImageView
.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
MKAnnotationView *annotationView = nil;
annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
if(!annotationView)
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:person reuseIdentifier:@"pin"];
else
annotationView.annotation = annotation;
UIImageView *avatarImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 25, 25)];
avatarImage.image = [UIImage imageNamed:avatarName];
[annotationView setImage:nil];
avatarImage.layer.masksToBounds = YES;
UIView *avatarView = [[UIView alloc] initWithFrame:CGRectMake(-7, 23, 30, 30)];
avatarImage.backgroundColor = [UIColor clearColor];
avatarView.layer.cornerRadius = 15.0f;
[avatarView addSubview:avatarImage];
[annotationView addSubview:avatarView];
return annotationView;
}
After all:
This is What I want :)
But sometimes when I tap this annotation didSelectAnnotationView:
isn't called. I know why, coz my UIView
with my image out of MKAnnotation
.
I changed background color of MKAnnotation
:
When I tap this red region didSelectAnnotationView:
is called.
SO, question is how can I change frame of this MKAnnotationView
so that my UIView
will not be outside?
P.S. I tried change frame, doesn't work :D
P.S.S Sorry for my English :(