0
在我的mapview上,當用戶滾動並停止時,我想將我的web服務發送到地圖中心的緯度。我的問題是我想在用戶停止在地圖上移動之後觸發事件。目前發生的事情是事件馬上被解僱。我目前使用的觸摸事件MKMapView觸摸事件
TouchesBegin TouchesCancelled TouchesEnded
這是我所看到的在一個模擬器上
TouchesBegin總是被調用運行時,當用戶觸摸屏幕時 TouchesCancelled被稱爲如果我移動地圖。但它在觸摸開始後立即調用並且 不當用戶停止移動地圖時 當用戶剛剛觸摸地圖並在觸摸開始後立即調用時,會調用TouchesEnd。
#region ToucheEvents
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
base.TouchesBegan(touches, evt);
Console.WriteLine("Touchs Begin");
_cancelTokenSource.Cancel();
_operationMode = ParkingOperationMode.ParkingNotAvailable;
UpdateUi();
}
public override void TouchesCancelled(NSSet touches, UIEvent evt)
{
base.TouchesCancelled(touches, evt);
Console.WriteLine("Touchs Cancelled");
MapViewOnRegionChanged();
}
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
base.TouchesEnded(touches, evt);
Console.WriteLine("Touched Ended");
_cancelTokenSource.Cancel();
}
#endregion
private void MapViewOnRegionChanged()
{
_cancelTokenSource = new CancellationTokenSource();
_cancelToken = _cancelTokenSource.Token;
_cancelToken.Register(CancelCallBack);
if (Utility.ValidateOnlineStatus())
{
ViewDef.ShowLoadingAnimation();
Utility.AddNetworkConnection();
Task.Run(() =>
{
Thread.Sleep(1000);
if (!_cancelToken.IsCancellationRequested)
{
_cancelToken.ThrowIfCancellationRequested();
Console.WriteLine("Firing GetLocation");
GetParkingLocation();
}
else {
Console.WriteLine("Location Cancelled");
}
}, _cancelToken);
}
}