I'm currently rotating the image property of an MKAnnotationView using CGAffineTransformMakeRotation. However, the whole view in this case gets rotated, as well as the callout bubble. So I followed the suggestion within MKAnnotationView Only Rotate the Image property, and am now creating a UIImageView and adding it as a subview to MKAnnotationView. The image displays and rotates now without issue. However, now the MKAnnotationView doesn't respond to a touch event. I need it to behave just as it did before - on tap/touch it should show the callout bubble. Any ideas what I need to do?
Initial way I tried (which rotates callout bubble):
MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
aView.image = [UIImage imageNamed:@"mapPin.png"];
float newRad = degreesToRadians(degreesToRotate);
[aView setTransform:CGAffineTransformRotate(CGAffineTransformIdentity, newRad)];
Using a UIImageView and adding as a subview:
MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
UIImageView *iv = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mapPin.png"]];
iv.userInteractionEnabled = YES;
[aView addSubview:iv];
aView.canShowCallout = YES;
Update I tried to add a gesture recognizer, though it doesn't work. imageTapped method doesn't get called when I tap on the UIImageView within the MKAnnotationView on the map. This is within the method: - (MKAnnotationView *)mapView:(MKMapView *)mView viewForAnnotation:(id )annotation
MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
UIImageView *iv = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mapPin.png"]];
iv.userInteractionEnabled = YES;
iv.exclusiveTouch = NO;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
[iv addGestureRecognizer:tapGesture];
[aView addSubview:iv];