开发者

UISwipeGestureRecognizer not working in iOS 4.3

This code worked fine in prior iOS versions but now in iOS 4.3 it's no longer working. Anyone have any suggestions on what needs to be corrected?

In the FinishedLaunching event I call AddSyncGesture and then whenever the device is rotated I have a notifier that calls the method as well as vertical changes with the orientation change so I have to remove and re-add it.

        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 == UIDeviceOrientati开发者_StackOverflow中文版on.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;
        }   
    }


This is what I use. Not sure it's the only possible way but works with no problems:

    protected void InitRecognizers()
    {
        var _swiperRight = new UISwipeGestureRecognizer();
        _swiperRight.Direction = UISwipeGestureRecognizerDirection.Right;
        _swiperRight.AddTarget(this, new MonoTouch.ObjCRuntime.Selector("SwipeNext"));
        this.View.AddGestureRecognizer(_swiperRight);
    }

    [Export("SwipeNext")]
    public virtual void Swipe(UIGestureRecognizer rec)
    {
        //your code here
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜