地图标注标题未在iOS 7.0中显示,但显示在6.0和7.1中

时间:2014-05-02 13:30:08

标签: ios ios7 mapkit

嘿,我正在开发基于地图的iOS应用程序,在iOS 6.0和7.1中,地图显示注释标题但不在7.0中。请告诉我是否有任何影响因素。我正在为注释使用自定义地图注释视图。 viewForAnnotation显示注释具有标题但未显示。为什么??请告诉我。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
CusomeMapAnnotation *customMap = (CusomeMapAnnotation *)annotation;
CustomMapAnnotationView *pinAnnot = (CustomMapAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Location"];
if (!pinAnnot) {
    pinAnnot = [[CustomMapAnnotationView alloc] initWithAnnotation:customMap reuseIdentifier:@"Location"];
}
switch (customMap.bck_type) {
    case 0:
        pinAnnot.playMapPin.image = [UIImage imageNamed:@"play_NP_button.png"];
        pinAnnot.playMapPin.color = [UIColor colorWithRed:54.0/255.0 green:208.0/255.0 blue:120.0/255.0 alpha:1.0];
        break;
    case 1:
        pinAnnot.playMapPin.image = [UIImage imageNamed:@"play_city_button.png"];
        pinAnnot.playMapPin.color = [UIColor colorWithRed:191.0/255.0 green:83.0/255.0 blue:161.0/255.0 alpha:1.0];
        break;
    case 2:
        pinAnnot.playMapPin.image = [UIImage imageNamed:@"play_water_button.png"];
        pinAnnot.playMapPin.color = [UIColor colorWithRed: 39.0/255.0 green:169.0/255.0 blue:193.0/255.0 alpha:1.0];
        break;
    default:
        break;
}
pinAnnot.title=customMap.placeTitle;
if ([self isVideoAlreadySaved:customMap.videoFile])
{
    pinAnnot.playMapPin.progress = 1.0;
}

NSMutableDictionary *tempData;
for(int i=0;i<appDelegate.downloadQueue.count;i++)
{
    tempData=[appDelegate.downloadQueue objectAtIndex:i];
    if([[tempData objectForKey:@"Latitude"] doubleValue]==customMap.coordinate.latitude&&[[tempData objectForKey:@"Longitude"] doubleValue]==customMap.coordinate.longitude)
        pinAnnot.playMapPin.progress=[[tempData objectForKey:@"Progress"] doubleValue]/100;
}
pinAnnot.frame = CGRectMake(0, 0,200,150);
pinAnnot.playMapPin.transform =  CGAffineTransformMakeScale (customMap.scale, customMap.scale);
pinAnnot.canShowCallout = NO;
if (customMap.scale<0.25) {
    [pinAnnot bringSubviewToFront:[mapView.subviews lastObject]];
}
[pinAnnot setNeedsDisplay];
return pinAnnot;

}

pinAnnot显示它具有title的值,但不会显示在地图上。

用于.h中的customMap Annotation

@interface CustomMapAnnotationView : MKAnnotationView{
}
@property (nonatomic, strong) CusomeMapAnnotation *customMap;
@property (nonatomic, strong) STKSpinnerView *playMapPin;
@property (nonatomic ,strong) NSString *title;
-(void)needsLayoutWithZoomLevel:(int)zoomLevel;
@end

和.m

- (void)drawRect:(CGRect)rect

{     [super drawRect:rect];     NSMutableAttributedString * finalAttributedString = [[NSMutableAttributedString alloc] initWithString:_title];

[finalAttributedString addAttribute:NSBackgroundColorAttributeName value:[UIColor clearColor] range:NSMakeRange(0, finalAttributedString.length)];

[finalAttributedString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:fontsize+((map_zoomLevel-4)*1.2)] range:NSMakeRange(0, finalAttributedString.length)];

[finalAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, finalAttributedString.length)];

[finalAttributedString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0] range:NSMakeRange(0, finalAttributedString.length)];

[finalAttributedString addAttribute:NSStrokeColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, finalAttributedString.length)];

NSMutableParagraphStyle *mutParaStyle=[[NSMutableParagraphStyle alloc] init];
[mutParaStyle setAlignment:NSTextAlignmentCenter];
[finalAttributedString addAttribute:NSParagraphStyleAttributeName value:mutParaStyle range:NSMakeRange(0, finalAttributedString.length)];

[finalAttributedString drawInRect:CGRectMake(0,_playMapPin.frame.origin.y+_playMapPin.frame.size.height+1, 200, 100)];


_playMapPin.wellThickness = 5.0;
[_playMapPin setBackgroundColor:[UIColor clearColor]];
[self addSubview:_playMapPin];

}

iOS 6和iOS 7的图片显示了问题。

iOS 6

enter image description here

请注意,使用NSAttributedString显示文本。

0 个答案:

没有答案
相关问题