none
WinJS.UI.FlipView中使用MSGesture无法捕获手势 RRS feed

  • 问题

  • 向Flipview中的img控件添加了MSGesture的手势事件,但是始终无法捕获消息。具体代码如下:

    function ready() {

    var flipview = element.querySelector("#picView");.winControl;
                WinJS.UI.setOptions(flipview, {
                    itemTemplate: flipRender,
                    itemDataSource: dataSource,
                    onpagecompleted: flipPagecompleted
                });

    .....

    }

    function flipRender(){

            var element = document.createElement("div");
            element.className = "picViewTemplate";
            WinJS.Utilities.setInnerHTMLUnsafe(element, "<img /><video controls='controls'/><h2>...</h2>");
            var img = element.querySelector("img");
            var video = element.querySelector("video");
            video.style.display = "none";
            var title = element.querySelector("h2");
            title.className = "picNameTemplate";

            // set the gesture event handlers
            img.addEventListener("MSPointerDown", onPointerDown, false);
            img.addEventListener("MSPointerUp", onPointerUp, false);
            img.addEventListener("MSPointerMove", onPointerMove, false);

            img.addEventListener("MSGestureStart", onGestureStart, false);
            img.addEventListener("MSGestureChange", onGestureChange, false);
            img.addEventListener("MSGestureEnd", onGestureEnd, false);
            img.addEventListener("MSInertiaStart", insertiaStart, false);

            var targetGesture = new MSGesture();
            targetGesture.target = img;
            img.gesture = targetGesture;

    .....

    }

    function onPointerDown(e) {
            if (e.currentTarget.gesture.target == null)
                e.currentTarget.gesture.target = e.currentTarget;
            try {
                e.currentTarget.gesture.addPointer(e.pointerId);
            }
            catch (e) { }
        }

        function onPointerUp(e) {
        }

        function onPointerMove(e) {
            if (e.currentTarget.gesture.target == null)
                e.currentTarget.gesture.target = e.currentTarget;
            try {
                var pps = e.getIntermediatePoints(e.target);
                e.currentTarget.gesture.processMoveEvents(pps);
            }
            catch (e) { }
        }

        function onGestureStart(e) {
            var test = e;
        }

        function onGestureChange(e) {
        }

        function onGestureEnd(e) {
        }

        function insertiaStart(event) {
        }

    能够跟到onPointerDown的消息,但是onGestureStart, onGestureChange, onGestureEnd以及insertiaStart都收不到。请假如何使Flipview中的控件相应手势消息。谢谢!

    2014年4月29日 2:35

答案

  • 我记得有篇blog有提到这个问题,我去找找看。

    ==update==

    http://blogs.msdn.com/b/wsdevsol/archive/2013/02/16/where-did-all-my-gestures-go.aspx

    你的那些手势应该被FlipView处理了,所以导致传递不到image中,目前也没有一个很好的解决方案,不过你能说说你想要达成什么样的效果,看看是否有什么办法可以绕过?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    2014年4月30日 3:11
    版主