1
此代碼在以前的iOS版本中運行良好,但現在在iOS 4.3中不再有效。任何人都有什麼需要改正的建議?UISwipeGestureRecognizer不能在iOS 4.3中工作
在FinishedLaunching事件中,我調用AddSyncGesture,然後每當設備旋轉時,我有一個通知程序調用該方法以及垂直更改方向更改,因此我必須刪除並重新添加它。
UISwipeGestureRecognizer sgr = null;
public void AddSyncGesture()
{
try {
if (sgr != null)
window.RemoveGestureRecognizer(sgr);
else
sgr = new UISwipeGestureRecognizer();
} catch (Exception ex) {
Logger.LogException(ex.Message, ex, "AddSyncGesture");
}
try {
sgr.NumberOfTouchesRequired = 2;
if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeRight || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeLeft)
sgr.Direction = UISwipeGestureRecognizerDirection.Left | UISwipeGestureRecognizerDirection.Right;
else
sgr.Direction = UISwipeGestureRecognizerDirection.Up | UISwipeGestureRecognizerDirection.Down;
sgr.Delegate = new SwipeRecognizerDelegate();
sgr.AddTarget(this, SwipeSelector);
window.AddGestureRecognizer(sgr);
} catch (Exception ex) {
Logger.LogException(ex.Message, ex, "AddSyncGesture");
}
}
Selector SwipeSelector
{
get { return new Selector("HandleSwipe"); }
}
[Export("HandleSwipe")]
public void HandleSwipe(UISwipeGestureRecognizer recognizer)
{
if (Utils.CanSync)
Application.Synchronizer.Synchronize(true,Application.ProgressView);
}
class SwipeRecognizerDelegate : MonoTouch.UIKit.UIGestureRecognizerDelegate
{
public override bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
{
return true;
}
}
如果您設置所需的觸摸次數爲2,它仍然工作嗎? – Neal 2011-03-15 15:10:36
是的,它工作仍然沒有問題。我在4.3版本的真實設備上嘗試過。 – Scarlaxx 2011-03-15 16:12:35
謝謝,我會繼續關注它。我實際上將我的GR添加到FinishedLaunching事件的窗口中,因此它可用於應用程序範圍。在4.3之前工作。 – Neal 2011-03-15 16:25:17