2013-10-31 53 views

回答

2

我通過手動調用KVO willChangeValuedidChangeValue方法解決了Coordinate屬性的設置方法。就像這樣:

public override CLLocationCoordinate2D Coordinate 
    { 
     get 
     { 
      var loc = UserInfo.Activity.MapLocation.Location; 
      return new CLLocationCoordinate2D(loc.Latitude, loc.Longitude); 
     } 

     set 
     { 
      WillChangeValue("coordinate"); 

      //Save value here to some backing store 
      //e.g. _coordinate = value 

      DidChangeValue("coordinate"); 
     } 
    } 

動畫會這樣:

UIView.AnimateNotify(1.0,() => { 
    myAnnotation.Coordinate = targetCoordinates; 
}, finished => { 

}); 

我也有問題,如果添加多個註釋,其中一人是從左上角移動。我通過在後臺線程上面包裝動畫代碼來解決它:

System.Threading.ThreadPool.QueueUserWorkItem(state => { 
    InvokeOnMainThread(() => { 
     UIView.AnimateNotify(1.0,() => { 
      myAnnotation.Coordinate = targetCoordinates; 
      secondAnnotation.Coordinate = secondCoordinates; 
     }, finished => { 

     }); 
    }); 
}); 

這有點不好意思,但它有效。它給出了調用AddAnnotations機會的方法,然後更新座標。你或許可以對動畫延遲做同樣的事情,但它對我來說不起作用。

相關問題