Kineticjs: Rotate an Image with a two Finger Touch Gesture?

筅森魡賤 提交于 2019-12-08 06:28:22

问题


I want to use Kineticjs on a mobile device to rotate an image with a two finger rotation gesture.

Displaying an image is described here. Which is basically this:

<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v5.0.1.min.js"></script>
<script defer="defer">
  var stage = new Kinetic.Stage({
    container: 'container',
    width: 578,
    height: 200
  });
  var layer = new Kinetic.Layer();

  var imageObj = new Image();
  imageObj.onload = function() {
    var yoda = new Kinetic.Image({
      x: 200,
      y: 50,
      image: imageObj,
      width: 106,
      height: 118
    });

    // add the shape to the layer
    layer.add(yoda);

    // add the layer to the stage
    stage.add(layer);
  };
  imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/yoda.jpg';

</script>

Adding touch events can be done with

imageObj.on('touchmove', function() {
       // do something
});

How can I rotate an image with a two finger touch gesture around the center of the image?


回答1:


You can use HammerJS with KineticJS (from Kinetic v5.1.0) for gesture events:

  var startRotate = 0;
  var hammertime = Hammer(image);
  hammertime.on("transformstart", function(e) {
    startRotate = image.rotation();
  }).on("transform", function(e) {
    image.rotation(startRotate + e.gesture.rotation);
    layer.draw();
  });

Demo



来源:https://stackoverflow.com/questions/22239443/kineticjs-rotate-an-image-with-a-two-finger-touch-gesture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!