iphone - UISwipeGestureRecognizer 在 iOS 4.3 中不起作用

标签 iphone ios xamarin.ios ios4

此代码在以前的 iOS 版本中运行良好,但现在在 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;
        }   
    }

最佳答案

这是我用的。不确定这是唯一可能的方法,但没有问题:

    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
    }

关于iphone - UISwipeGestureRecognizer 在 iOS 4.3 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5301316/

相关文章:

iphone - 使用 loadNibNamed 会导致内存泄漏

iphone - 在 iOS 设备上处理触摸事件

ios - 如果不快速执行任何操作,如何重复本地通知

c# - 旋转时 UIPageViewController 的 NSInternalInconsistencyException

iphone - Xcode 4 : How do you view the console?

iphone - 您如何在启动时播放音乐?

iphone - 为键盘切换 UIPicker

ios - 缺少 iOS 分发签名身份/"Certificate has an invalid issuer"

c# - 我不能将 null 作为标题传递给 MonoTouch 中的 UIActionSheet 构造函数有什么原因吗?

ios - 如何实例化 ARSCNView