Kineticjs:用双指触摸手势旋转图像? [英] Kineticjs: Rotate an Image with a two Finger Touch Gesture?

查看:124
本文介绍了Kineticjs:用双指触摸手势旋转图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在移动设备上使用 Kineticjs 以双指旋转手势旋转图像。

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>

添加触摸事件可以用

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

如何围绕图像中心用双指触摸手势旋转图像?

推荐答案

您可以使用 HammerJS KineticJS (来自Kinetic v5.1.0)用于手势事件:

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();
  });

演示

这篇关于Kineticjs:用双指触摸手势旋转图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆