我有一个带注释的MKMapView(也是一个UIPopoverControllerDelegate).这个MapView在MKTestMapView.h文件中有一个UIPopoverController* popoverController在@interface中定义的和一个已@property (nonatomic, retain) UIPopoverController* popoverController;定义的@interface部分外部.此控制器@synthesized位于MKTestMapView.m文件中,并在该- (void)dealloc部分中发布.此MapView中的注释已rightCalloutAccessoryView定义为以下内容:
- (void)mapView:(MKMapView *)mapView2 annotationView:(MKAnnotationView *)aview calloutAccessoryControlTapped:(UIControl *)control{
...
CGPoint leftTopPoint = [mapView2 convertCoordinate:aview.annotation.coordinate toPointToView:mapView2];
int boxDY=leftTopPoint.y;
int boxDX=leftTopPoint.x;
NSLog(@"\nDX:%d,DY:%d\n",boxDX,boxDY);
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
popoverController.delegate = self;
CGSize maximumLabelSize = CGSizeMake(320.0f,600.0f);
popoverController.popoverContentSize = maximumLabelSize;
CGRect rect = CGRectMake(boxDX, boxDY, 320.0f, 600.0f);
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
...
}
Run Code Online (Sandbox Code Playgroud)
现在这里有趣的部分.首先,我不确定我是否需要maximumLabelSize和rect相同的尺寸.我是popovercontroller的新手,所以我一直在玩这个...
好吧,popover显示.现在要解雇它.我可以点击mapView2上的任何地方,然后popover消失......但如果他们改变了什么,我需要用户点击视图中的按钮.URGH!
文档显示:
要以编程方式关闭弹出框,请调用popover控制器的dismissPopoverAnimated:方法.
好吧,问题在于:通过定义popoverController的工作原理,你在显示的弹出窗口的视图 …