iOS上的Flex点击响应不佳

时间:2012-06-10 02:16:54

标签: ios flex adobe touch

我们的应用中有几个项目渲染器,我们注意到这些UI元素对水龙头的响应能力差别很大。

示例:

    private function setupClickHandling():void
    {
        //this.addEventListener(TouchEvent.TOUCH_TAP, clickHandler);
        this.addEventListener(MouseEvent.CLICK, clickHandler);
    }

    protected function clickHandler(e:Object):void
    {
        var event:ItemClickEvent = 
                        new ItemClickEvent(ItemClickEvent.ITEM_CLICK, true);
        event.item = data;
        event.index = itemIndex;
        dispatchEvent(event);
    }

使用MouseEvent.CLICK时,有时点击不会注册为实际点击,即使控件在“向下”状态下花费一点时间。这是最令人沮丧的,因为用户认为控件已被触发,但除了灰色背景闪光之外没有任何其他事情发生,因为没有触发点击事件。

使用TouchEvent.TOUCH_TAP时,点击会变得响应,有时列表项会在列表拖动时触发。我认为只要中心点没有明显移动,无论持续时间有多短,水龙头界面都会记录水龙头,并且只要检测到足够的移动,水龙头就不会被记录。相反,似乎发生的事情是点击事件在事件的下部注册,而不是注册。

那么,有没有办法增加Click的灵敏度,或者降低Tap的灵敏度?

或者理想情况下,始终将水龙头注册为实际水龙头?

1 个答案:

答案 0 :(得分:1)

您可以滚动自己的点按手势。我就是这样做的..

public function BaseItemRenderer()
    {
        super();
        Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
        this.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
        this.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
        this.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
    }

    protected var touching:Boolean;
    protected var touchStartTime:int;
    protected var touchStartX:Number;
    protected var touchStartY:Number;

    private function onTouchBegin(e:TouchEvent):void
    {
        trace("onTouchBegin");
        touching = true;
        touchStartTime = getTimer();
        touchStartX = e.stageX;
        touchStartY = e.stageY;
    }

    private function onTouchMove(e:TouchEvent):void
    {
        //
    }

    protected static const TAP_MIN_DURATION:int = 0;
    protected static const TAP_MAX_DURATION:int = 1000;
    protected static const TAP_MIN_DISTANCE:Number = 0;
    protected static const TAP_MAX_DISTANCE:Number = 40;

    private function onTouchEnd(e:TouchEvent):void
    {

        if(touching)
        {
            touching = false;
            var duration:int = getTimer()-touchStartTime;
            var distanceX:Number = e.stageX - touchStartX;
            var distanceY:Number = e.stageY - touchStartY;
            var distance:Number = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
            trace("onTouchEnd duration:" + duration + " distance:" + distance);

            if(duration >= TAP_MIN_DURATION &&
                duration <= TAP_MAX_DURATION &&
                distance >= TAP_MIN_DISTANCE &&
                distance <= TAP_MAX_DISTANCE)
            {
                onTap(e.target);
            }
        }

    }