我试图让一个弹出窗口出现在地图工具包的注释点上,但是在注解视图属性中找不到" rect“来使用调用uipopovercontroller的rect方法。如果在地图工具包上给出一个注解,如何找到合适的“框架”?
为了给paul更多的信息,这里是我的尝试:我已经使用了:
- (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附近。
发布于 2010-05-05 05:13:59
好吧,
以下是我发现的迄今为止唯一的解决方法:
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绘制好自己后释放它。
是黑的,但很干净。
发布于 2010-06-26 22:40:25
此线程中第一个示例的问题在于对presentPopoverFromRect:inView:permittedArrowDirections:animated:.的调用inView:参数的值不正确。应该是view.rightCalloutAccessoryView。
也就是说,矩形的坐标是相对于rightCalloutAccessoryView的。
通过此更改,行为将类似于地图应用程序,这似乎是正确的。
发布于 2010-05-04 15:27:52
如果您有MKAnnotationView,并且您暗示您有,那么您可以使用它的frame属性,因为它是一个UIView子类。
https://stackoverflow.com/questions/2763284
复制相似问题