Я использую карту в своем приложении. Для сброса булавки я хочу установить изображение пользователя вместо булавки по умолчанию.
Я загружаю изображение пользователя и устанавливаю его в соответствии с кодом, который я вставляю ниже.
Для разных масштабов устройств я использую имя изображения в соответствии с масштабом устройства, например,
1 Для устройств без сетчатки - pin.png (размер 30 x 30)
2 Для устройств Retina - [email protected] (размер 60 x 60)
3 Для устройств 6+ - [email protected] (размер 90 x 90)
Здесь для 1 и 2 работают нормально, и изображение загружается идеально, но для 6+ (3-кратный масштаб) он не работает
В чем проблема:
Для 6+ я загружаю изображение pin @ 3x, но на карте его размер составляет 90 x 90, что должно быть 30 x 30. Поскольку это просто работает для изображений, когда мы используем из пакета приложений.
Для [email protected] он отлично работает и показывает 2-кратное изображение размером 30 x 30.
Я также попробовал решение ниже, установив масштаб изображения, но не работает
MKPinAnnotationView: доступно ли более трех цветов?
Я изо всех сил старался объяснить реальную проблему. Может ли какое-нибудь руководство, пожалуйста, если мне что-то не хватает или требуется что-то установить?
Код
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKPinAnnotationView *annotationView = nil;
if ([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
if ([annotation isKindOfClass:[KPAnnotation class]])
{
//Custom annotation class for pin drop
KPAnnotation *a = (KPAnnotation *)annotation;
annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
if (annotationView == nil)
{
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:[a.annotations anyObject]
reuseIdentifier:@"pin"];
}
//Image View to add subview in MKPinAnnotationView
UIImageView *imageView = [[UIImageView alloc] init];
UIImage * image = [UIImage imageNamed:@"pin.png"];
imageView.image=image;
//Test URL - see image name here
NSString *readAWSURL=@"<domainname.com>/[email protected]";
//Downloading image here to load with async way (SDWebImage)
[imageView sd_setImageWithURL:[NSURL URLWithString:readAWSURL] placeholderImage:[UIImage imageNamed:@"pin.png"]];
annotationView.image=imageView.image;
[annotationView addSubview:imageView];
annotationView.canShowCallout = YES;
}
return annotationView;
}