我想把这个OBJC片段翻译成Xamarin表单自定义渲染,我的语法目前无法正常工作。它在引脚拖动过程中崩溃而没有任何错误。
我现在拥有的是什么
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
var nativeMap = Control as MKMapView;
nativeMap.ChangedDragState-= OnDragState;
}
if (e.NewElement != null)
{
var formsMap = (CustomMap)e.NewElement;
var nativeMap = Control as MKMapView;
nativeMap.ChangedDragState+= OnDragState;
}
}
private void OnDragState(object sender, MKMapViewDragStateEventArgs e)
{
var NewState = e.NewState;
var OldState=e.OldState;
var ShowAnnotation=e.AnnotationView;
if (OldState==MKAnnotationViewDragState.Dragging)
{
}
if (NewState == MKAnnotationViewDragState.Ending)
{
CLLocationCoordinate2D pinAt = ShowAnnotation.Annotation.Coordinate;
var droppedLoc = new CLLocation(pinAt.Latitude, pinAt.Longitude);
geocodeLocation(droppedLoc);
}
}
基于您展示的ObjC:
public override void ChangedDragState(MKMapView mapView, MKAnnotationView annotationView, MKAnnotationViewDragState newState, MKAnnotationViewDragState oldState)
{
if (oldState == MKAnnotationViewDragState.Dragging)
{
}
if (newState == MKAnnotationViewDragState.Ending)
{
var pindropped = annotationView.Annotation.Coordinate;
var droppedLoc = new CLLocation(pindropped.Latitude, pindropped.Longitude);
geocodeLocation(droppedLoc);
mapView.AddAnnotation(_addressAnnotation);
}
}
注意:你没有为geocodeLocation
和_addressAnnotation
展示ObjC,所以你还需要翻译那些......