简体   繁体   English

UISwipeGestureRecognizer在iOS 4.3中不起作用

[英]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. 该代码在以前的iOS版本中运行良好,但在iOS 4.3中现在不再起作用。 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. 在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;
        }   
    }

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
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM