当我在地图中选择mkannotation时,我正在寻找显示视图的解决方案。在图片中:
如果您选择了mkannotation,则会显示底部的视图。我有办法,但我不知道它是否是最好的。它只是在地图下显示视图,就像一般视图的子视图一样,但问题是我看到它在地图上方隐藏了一部分,我不知道知道如何检测用户点击地图以隐藏个人资料的视图。
提前致谢
编辑1。 使用这段代码,我会收到错误,如果我修复它会将错误添加到.view中,这些会消失,但是当我选择一个mkannotation时它就不会出现任何错误。
答案 0 :(得分:1)
第一次创建i YourViewController.xib并在mapviewcontroller中使用此代码:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
if(![view.annotation isKindOfClass:[MKUserLocation class]]) {
YourViewController *calloutView = (YourViewController *)[[[NSBundle mainBundle] loadNibNamed:@"YourViewController" owner:self options:nil] objectAtIndex:0];
CGRect calloutViewFrame = calloutView.frame;
calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height);
calloutView.frame = calloutViewFrame;
[calloutView.calloutLabel setText:[(locationAnnotation*)[view annotation] title]];
[calloutView.CallDattabel setText:[(locationAnnotation*)[view annotation] subtitle]];
[calloutView.status setText:[(locationAnnotation*)[view annotation] status]];
[calloutView.ImageSate setImage:[(locationAnnotation*)[view annotation] image ]];
[view addSubview:calloutView];
}
}
-(void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view {
for (UIView *subview in view.subviews ){
[subview removeFromSuperview];
}
}
我希望这段代码对你有用