问题
I am updating my browser app to support Windows Phone 8.1 and I noticed the MSGestureHold
event is not raised.
To reproduce this error,
- Download the MS Mini-browser Sample.
- Upgrade the project to WP8.1 project in Visual Studio 2013 and add
IsScriptEnabled="True"
. - Run the project on WP8.1 emulator or device
- Navigate to this touch and mouse example.
- Scroll down to the
Sample 1: handling the hold gesture
section and click the IE11 users test.
Notice that MSGestureHold
is not working.
However the project is working when tested in
- Default Windows Phone Internet Explorer app for WP8 and WP8.1
- WebBrowser control in WP8 app.
Is this a bug?
回答1:
I guess this is the WebBrowser control's bug.
I test several gesture events with WebBrowser control for WP8.1, such as pointerdown,MSGestureHold,MSGestureChange,and MSGestureTap. Finally, pointerdown, MSGestureChange and MSGestureTap can be triggered normally,except MSGestureHold. So I guess this is a bug.
回答2:
This code works fine in webview for WPhone 8.1 apps :
var init = function(){
var myState = // context
var target = // DOM variable target
var msg = new MSGesture();
msg.target = target;
target.addEventListener("MSGestureHold", function (evt) { buttonTactileListener.apply(myState, [evt, msg]); }, false);
target.addEventListener("pointerdown", function (evt) { buttonTactileListener.apply(myState, [evt, msg]); }, false);
target.addEventListener("MSGestureEnd", function (evt) { buttonTactileListener.apply(myState, [evt, msg]); }, false);
}
var buttonTactileListener = function (evt, msgesture) {
var myState = this;
if (evt.type == "pointerdown") {
msgesture.addPointer(evt.pointerId);
return;
}
if (evt.type == "MSGestureHold") {
///do something
return;
}
if (evt.type == "MSGestureEnd") {
// renew instance of handler
msgesture = new MSGesture();
msgesture.target = evt.target;
return;
}
}
来源:https://stackoverflow.com/questions/23209243/msgesturehold-is-ignored-by-webbrowser-control-for-windows-phone-8-1