当地图缩放时,针上的弹出不会移动

时间:2014-02-28 06:58:54

标签: ios mkmapview mkannotation mkannotationview apple-maps

当点击pin(注释)时显示弹出视图,它显示正常,此后当我放大或缩小地图时,弹出窗口没有根据地图缩放移动到。所以我得到附加图像中的问题。 如何根据地图上受尊重的图钉移动弹出窗口(何时缩放地图)?

任何建议都非常有用。

-(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;
        }
    }

}

Issue am showing with arrow in the attached image.

提前致谢

1 个答案:

答案 0 :(得分:1)

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

作为替代方案,请考虑弹出窗口可能不是正确的工具,而custom callout可能是更好的解决方案。

相关问题