Skip to content

Commit d008535

Browse files
committed
修复ios marker icon 无法响应 click 事件的bug
1 parent 5c701ea commit d008535

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

ios/RCTBaiduMap/Views/OverlayMarker.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,21 @@ - (void)updateAnnotation:(BMKPointAnnotationPro *)annotation {
8080
}
8181

8282
- (void)updateAnnotationView:(BMKPointAnnotationPro *) annotation image:(UIImage *)image {
83-
annotation.annotationView.image = image;
8483
_iconImage = image;
8584
NSLog(@"annotationView width: %f, height: %f", _icon.size.width, _icon.size.height);
8685
if (_icon.size.height > 0 && _icon.size.width > 0) {
87-
annotation.annotationView.image = NULL;
88-
CGRect frame = CGRectMake(-_icon.size.width / 2, -_icon.size.height / 2, _icon.size.width, _icon.size.height);
86+
annotation.annotationView.image = nil;
87+
CGRect frame = CGRectMake(0, 0, _icon.size.width, _icon.size.height);
8988
if (_imageView == nil) {
9089
_imageView = [[UIImageView alloc] initWithImage:image];
9190
[annotation.annotationView addSubview:_imageView];
9291
}
9392
_imageView.frame = frame;
93+
annotation.annotationView.frame = frame;
9494

9595
} else {
9696
annotation.annotationView.image = image;
97+
annotation.annotationView.frame = CGRectMake(0, 0, CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
9798
}
9899
annotation.annotationView.pinColor = [self getPinAnnotationColor];
99100
}
@@ -119,12 +120,9 @@ - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex {
119120
[_annotation updatePaopaoView];
120121
});
121122
} else if([subview isKindOfClass:[OverlayMarkerIcon class]]) {
122-
UIGraphicsBeginImageContextWithOptions(subview.frame.size, YES, [UIScreen mainScreen].scale);
123-
[subview.layer renderInContext:UIGraphicsGetCurrentContext()];
124-
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
125-
UIGraphicsEndImageContext();
126123
dispatch_async(dispatch_get_main_queue(), ^{
127124
_annotation.annotationView.image = nil;
125+
_annotation.annotationView.frame = subview.frame;
128126
[_annotation.annotationView addSubview:subview];
129127
});
130128
}

0 commit comments

Comments
 (0)