1

单击图钉(注释)时显示弹出视图,它显示正常,之后当我放大或缩小地图时,弹出视图不会根据地图缩放移动到。所以我得到了附件图像中的问题。如何根据地图上受人尊敬的图钉移动弹出窗口(当缩放地图时)?

任何建议都非常有帮助。

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{

    NSString *strTitle = [NSString stringWithFormat:@"%@",[view.annotation title]];
    NSMutableDictionary *dict;
    NSMutableArray *temp = annotationArray;
    for (int i = 0; i<[temp count]; i++)
    {
        dict = (NSMutableDictionary*)[temp objectAtIndex:i];
        NSString *strAddress = [NSString stringWithFormat:@"%@",[dict valueForKey:@"name"]];
        if([strAddress isEqualToString:strTitle]) {

            [mapView deselectAnnotation:view.annotation animated:YES];

            detailsViewController = [[PopOverViewController alloc] initWithNibName:@"PopOverViewController" bundle:nil];
//            [viewsPassage addObject:view];

//            NSOrderedSet *orderedSet = [[NSOrderedSet alloc] initWithArray:viewsPassage];
//            viewsPassage = [[NSMutableArray alloc] initWithArray:[orderedSet array]];
            if ([viewsPassage containsObject:view]) {
                NSLog(@"present");
                [self.poc dismissPopoverAnimated:YES];
            }

            self.poc = [[UIPopoverController alloc] initWithContentViewController:detailsViewController];
            self.poc.contentViewController.view.alpha = 0;
            [viewsPassage addObject:userMapView];
            [self.poc setPassthroughViews:viewsPassage];
            [detailsViewController.textLabel setText:strAddress];
            //size as needed
            self.poc.popoverContentSize = CGSizeMake(320, 400);
            //show the popover next to the annotation view (pin)
            CGRect popOverFrame = view.bounds;
            popOverFrame.size.width = 14;
            popOverFrame.size.height = 14;

            [self.poc presentPopoverFromRect:popOverFrame inView:view
               permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
            break;
        }
    }

}

问题在附图中用箭头显示。

提前致谢

4

1 回答 1

1

像所有视图一样,您的弹出框是相对于视图坐标定位的,但您希望它像根据地图坐标定位一样移动。这不会自动发生。相反,您需要在地图区域更改时移动弹出框。地图视图委托协议中有一些方法可以让您的地图委托在区域更改时采取行动;看看-mapView:regionDidChangeAnimated:

作为替代方案,请考虑弹出框可能不是该工作的正确工具,而自定义标注可能是更好的解决方案。

于 2014-03-02T16:23:23.083 回答