触摸时,MapView注释会更改其图层顺序

时间:2013-03-12 13:57:13

标签: iphone xcode

小问题,我在地图视图上有一些注释。有时它们在彼此非常接近时往往会重叠,这没关系,但是当我触摸它们时,它们会切换它们的层位置。那些在后面的人现在在前面,反之亦然。

所以我检查了我的didSelectAnnotation函数,但是该函数中没有任何代码,所以它不可能是它。

我想不出任何可能导致它的事情。

你知道如何修复它所以不会改变层位置吗?

这是我的viewForAnnotation代码:

annImg = [[szAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];


        szPointAnnotation *pointAnnotation = annotation;
        if (appDelegate.homePage || ([pointAnnotation.tag intValue] >= 10000))
        {
            annImg.canShowCallout = NO;
            annImg.backgroundColor = [UIColor clearColor];
            annImg.frame = CGRectMake(0, /*0*/-78, 70, /*78*/156);



            UIImageView *currentUserPictureView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 60, 60)];

            int newTag = [pointAnnotation.tag intValue]-10000;
            UIImage *currentUserPicture;
            if ([pointAnnotation.tag intValue] >= 10000) {
                currentUserPicture = [UIImage imageWithData:[usersData getKeyForIndexWithKey:@"UserImageData" forIndex:newTag]];
            }else{
                currentUserPicture = [UIImage imageWithData:[usersData getKeyForIndexWithKey:@"UserImageData" forIndex:[pointAnnotation.tag intValue]]];
            }


            currentUserPictureView.image = currentUserPicture;
            userLocationButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 70, 78)];
            [userLocationButton setBackgroundImage:[UIImage imageNamed:@"pin.png"] forState:UIControlStateNormal];
            [userLocationButton addTarget:self action:@selector(centerOnUser:) forControlEvents:UIControlEventTouchUpInside];

            if ([pointAnnotation.tag intValue] >= 10000) {
                userLocationButton.tag = newTag;
            }else{
                userLocationButton.tag = [pointAnnotation.tag intValue];
            }


            [userLocationButton setBackgroundColor:[UIColor clearColor]];
            [annImg addSubview:userLocationButton];
            [userLocationButton addSubview:currentUserPictureView];


            [userLocationButton release];
            [currentUserPictureView release];
            [currentUserPicture release];
        }

0 个答案:

没有答案