Ios 自定义用户位置图像未在pin上居中
所以我真的很困惑。我用过:Ios 自定义用户位置图像未在pin上居中,ios,mkmapview,mapkit,mkannotationview,userlocation,Ios,Mkmapview,Mapkit,Mkannotationview,Userlocation,所以我真的很困惑。我用过: - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { static NSString* AnnotationIdentifier = @"Annotation"; MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView de
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString* AnnotationIdentifier = @"Annotation";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (!pinView) {
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
if (annotation == mapView.userLocation){
customPinView.image = [UIImage imageNamed:@"303761_4417778996801_94858213_n.jpg"];
[customPinView.layer setMasksToBounds:NO];
[self setRoundedView:customPinView toDiameter:kPictureDiameter];
[customPinView.layer setBorderColor:[UIColor whiteColor].CGColor];
[customPinView.layer setBorderWidth:5.0f];
[customPinView.layer setShadowColor:[UIColor blackColor].CGColor];
[customPinView.layer setShadowOpacity:1.0f];
[customPinView.layer setShadowRadius:20.0f];
[customPinView.layer setShadowOffset:CGSizeMake(0, 0)];
[customPinView setBackgroundColor:[UIColor whiteColor]];
}
return customPinView;
} else {
pinView.annotation = annotation;
}
return pinView;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
静态NSString*AnnotationIdentifier=@“Annotation”;
MKPinAnnotationView*pinView=(MKPinAnnotationView*)[mapView出列可重用AnnotationViewWithIdentifier:AnnotationIdentifier];
如果(!pinView){
MKPinAnnotationView*customPinView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:AnnotationIdentifier];
if(注释==mapView.userLocation){
customPinView.image=[UIImage ImageName:@“303761_4417778996801_94858213_n.jpg”];
[customPinView.layer setMasksToBounds:否];
[自设置圆形视图:自定义PinView至直径:kPictureDiameter];
[customPinView.layer setBorderColor:[UIColor whiteColor].CGColor];
[customPinView.layer setBorderWidth:5.0f];
[customPinView.layer setShadowColor:[UIColor blackColor].CGColor];
[customPinView.layer setShadowOpacity:1.0f];
[customPinView.layer setShadowRadius:20.0f];
[customPinView.layer setShadowOffset:CGSizeMake(0,0)];
[customPinView setBackgroundColor:[UIColor whiteColor]];
}
返回customPinView;
}否则{
pinView.annotation=注释;
}
返回pinView;
}
将我自己的图像添加到用户位置pin。这就行了。但有两个问题:
任何帮助都将不胜感激。关于图像偏离中心,有两种想法:
MKAnnotationView
,而不是MKPinAnnotationView
。当我尝试使用MKPinAnnotationView
时,我的图像不再居中centerOffset
属性。如果您使用MKAnnotationView
,我认为您不需要这样做MKAnnotationView
图像上使用阴影,效果很好。你能和我们分享你的取整算法吗MKCircleView
时,它工作得很好,但我们要确保我们没有在那里做任何奇怪的事情(或使用任何其他绘图例程)从Pin切换到常规注释是完美的。好主意。对于阴影,这是取整方法,因为它是在层上操作的。