Skip to content

Commit

Permalink
修复ios marker icon 无法响应 click 事件的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lovebing committed Jun 13, 2020
1 parent 5c701ea commit d008535
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions ios/RCTBaiduMap/Views/OverlayMarker.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,21 @@ - (void)updateAnnotation:(BMKPointAnnotationPro *)annotation {
}

- (void)updateAnnotationView:(BMKPointAnnotationPro *) annotation image:(UIImage *)image {
annotation.annotationView.image = image;
_iconImage = image;
NSLog(@"annotationView width: %f, height: %f", _icon.size.width, _icon.size.height);
if (_icon.size.height > 0 && _icon.size.width > 0) {
annotation.annotationView.image = NULL;
CGRect frame = CGRectMake(-_icon.size.width / 2, -_icon.size.height / 2, _icon.size.width, _icon.size.height);
annotation.annotationView.image = nil;
CGRect frame = CGRectMake(0, 0, _icon.size.width, _icon.size.height);
if (_imageView == nil) {
_imageView = [[UIImageView alloc] initWithImage:image];
[annotation.annotationView addSubview:_imageView];
}
_imageView.frame = frame;
annotation.annotationView.frame = frame;

} else {
annotation.annotationView.image = image;
annotation.annotationView.frame = CGRectMake(0, 0, CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
}
annotation.annotationView.pinColor = [self getPinAnnotationColor];
}
Expand All @@ -119,12 +120,9 @@ - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex {
[_annotation updatePaopaoView];
});
} else if([subview isKindOfClass:[OverlayMarkerIcon class]]) {
UIGraphicsBeginImageContextWithOptions(subview.frame.size, YES, [UIScreen mainScreen].scale);
[subview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_async(dispatch_get_main_queue(), ^{
_annotation.annotationView.image = nil;
_annotation.annotationView.frame = subview.frame;
[_annotation.annotationView addSubview:subview];
});
}
Expand Down

0 comments on commit d008535

Please sign in to comment.