How*_*ack 12 iphone mkmapview mkannotationview ios4
我之前创建了一个自定义标注气泡作为MKAnnotationView的子视图,因为内置标注非常有限.这需要我在选择MKAnnotationView以考虑标注气泡大小时更改为MKAnnotationView的centerOffset.在iOS 4问世之前,这一切都完美无缺.现在,对于iOS 4,它完全忽略了我对centerOffset属性的更新,因此引脚和气泡似乎向下跳到右边(标注气泡的左上角现在位于引脚点所在的位置) .
有谁知道为什么这在iOS 4中发生了变化?我能做些什么来让MKMapView识别新的centerOffset吗?这是苹果推出的错误吗?
谢谢您的帮助!
小智 6
确保您使用的是MKAnnotationView而不是MKPinAnnotationView!您不能设置MKPinAnnotationView对象的centerOffset(当然,除非您是子类).
小智 0
我认为centerOffset您可以使用setRegion它在所有版本中都可以正常工作。
CGPoint point = [mapView convertCoordinate:selectedAnnotation.coordinate toPointToView:self.view];
CGRect frame = [customView frame];
frame.origin.y = point.y - frame.size.height;
frame.origin.x = point.x - frame.size.width / 2;
MKCoordinateRegion region = [mapView convertRect:frame toRegionFromView:self.view];
[mapView setRegion:region animated:YES];
Run Code Online (Sandbox Code Playgroud)