右侧标注按钮的 X 和 Y 坐标未准确放置我的视图
正如您在下面看到的,我使用 calloutaccessorycontrol 的坐标在我的地图视图上放置另一个视图。然而。它似乎从未将控件放置在 calloutaccessorycontrol 附近的任何位置。这很奇怪,因为我使用的是它的 x 和 y 坐标。
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
HotelInformationViewController *vc =
[[HotelInformationViewController alloc]initWithNibName:@"HotelInformationViewController"
bundle:nil control:control];
[self.view addSubview:vc.view];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil control:(UIControl *)control
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
self.view.bounds = CGRectMake(control.frame.origin.x, control.frame.origin.y, 286, 286); //As you can see here I am using the x and y to place the new control
}
return self;
}
As you can see below I am using the calloutaccessorycontrol's coordinates to place another view on my mapview. However. it never seems to place the control anywhere near the calloutaccessorycontrol. This is strange, because I am using its x and y coordinates.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
HotelInformationViewController *vc =
[[HotelInformationViewController alloc]initWithNibName:@"HotelInformationViewController"
bundle:nil control:control];
[self.view addSubview:vc.view];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil control:(UIControl *)control
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
self.view.bounds = CGRectMake(control.frame.origin.x, control.frame.origin.y, 286, 286); //As you can see here I am using the x and y to place the new control
}
return self;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要设置框架而不是边界。
但另一个问题是标注按钮的位置是相对于注释的弹出视图(而不是 self.view)。注释的弹出位置是相对于地图视图等的。
您需要使用
convertPoint:toView:
方法将标注的位置转换为 self.view 的坐标系。按如下方式修改 init 方法:
在上面的 init 方法中,您还必须调整酒店视图的框架,以便它不会显示在屏幕之外,如果标注靠近屏幕的右侧或底部边缘,则可能会发生这种情况。
然后在calloutAccessoryControlTapped方法中:
You need to set the frame instead of the bounds.
But the other problem is that the callout button's position is relative to the popup view of the annotation (not self.view). The annotation's popup position is relative to the map view, etc.
You need to convert the callout's position to the self.view's coordinate system using the
convertPoint:toView:
method.Modify the init method as follows:
In the init method above, you'll also have to adjust the hotel view's frame so that it doesn't show up off screen which could happen if the callout is near the right or bottom edge of the screen.
Then in the calloutAccessoryControlTapped method: