首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将uipopovercontroller的箭头放置在mapkit上的注释点

将uipopovercontroller的箭头放置在mapkit上的注释点
EN

Stack Overflow用户
提问于 2010-05-04 14:36:34
回答 5查看 8.1K关注 0票数 2

我试图让一个弹出窗口出现在地图工具包的注释点上,但是在注解视图属性中找不到" rect“来使用调用uipopovercontroller的rect方法。如果在地图工具包上给出一个注解,如何找到合适的“框架”?

为了给paul更多的信息,这里是我的尝试:我已经使用了:

代码语言:javascript
复制
- (void)mapView:(MKMapView *)mapView2 annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
    NSLog(@"annotationView...");
    MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager];
    int choice = 0;
    for (NSMutableDictionary *locationDictionary in [myGizmoClass searchResultsForResortLocation]) 
    {
        if([view.annotation.title isEqualToString:[locationDictionary objectForKey:@"name"]])
        {

            DetailViewTableStyleController *controller = [[DetailViewTableStyleController alloc] initWithlocationData:[[myGizmoClass searchResultsForResortLocation] objectAtIndex:choice] nibName:@"DetailViewTableStyle" bundle:[NSBundle mainBundle]];

            controller.categoryCode = [locationDictionary objectForKey:@"category_code"] ;

            //create a popover controller
            popoverControllerDetail = [[UIPopoverController alloc] initWithContentViewController:controller];

            // set contentsize
            [popoverControllerDetail setPopoverContentSize:CGSizeMake(320,480)];

            //present the popover view non-modal

            [popoverControllerDetail presentPopoverFromRect:view.rightCalloutAccessoryView.frame inView:mapView2 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

            [controller release];
            break;
        }
        choice = choice + 1;
    }
}

还有..。我在地图视图的左上角看到了一个弹出窗口。

有人能告诉我为什么吗?我正在尝试让它出现在pin/annotationview附近。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2010-05-05 05:13:59

好吧,

以下是我发现的迄今为止唯一的解决方法:

代码语言:javascript
复制
CGPoint annotationPoint = [mapView2 convertCoordinate:view.annotation.coordinate toPointToView:mapView2];
float boxDY=annotationPoint.y;
float boxDX=annotationPoint.x;
CGRect box = CGRectMake(boxDX,boxDY,5,5);
UILabel *displayLabel = [[UILabel alloc] initWithFrame:box];


[popoverControllerDetail presentPopoverFromRect:displayLabel.frame inView:mapView2 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[displayLabel release];

不好的地方是我假装把它放在注解的视图中。我只是获取注释视图的annotation.coordinate (MKMapKit样式坐标),并将坐标转换为屏幕坐标。然后,我创建了一个uilabel (在屏幕上获得一个支持帧的构造),放置在Annotation View的位置。然后,我告诉popovercontroller出现在该帧位置。

这是最重要的。我没有将uilabel添加到mapView2中。我只需在popovercontroller绘制好自己后释放它。

是黑的,但很干净。

票数 7
EN

Stack Overflow用户

发布于 2010-06-26 22:40:25

此线程中第一个示例的问题在于对presentPopoverFromRect:inView:permittedArrowDirections:animated:.的调用inView:参数的值不正确。应该是view.rightCalloutAccessoryView。

也就是说,矩形的坐标是相对于rightCalloutAccessoryView的。

通过此更改,行为将类似于地图应用程序,这似乎是正确的。

票数 2
EN

Stack Overflow用户

发布于 2010-05-04 15:27:52

如果您有MKAnnotationView,并且您暗示您有,那么您可以使用它的frame属性,因为它是一个UIView子类。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2763284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档