1

我有一些用于旋转图像的代码。但是,旋转中心不等于要旋转的图像的中心。

我已经设置了图像的中心,但我不知道如何设置旋转的中心。

以下是代码:

 // image code
var image = Titanium.UI.createImageView({
    backgroundImage:'test.png',
    width: 650,
    height: 650,
    center:{x:CenterX, y:CenterY},
    align:'center'
});
//rotation code
image.addEventListener('touchstart', function(e){
    var conv = e.source.convertPointToView({x: e.x, y:e.y}, win);

    var newAngle = Math.atan2(conv.y - 500, 380 - conv.x)* -(180 / Math.PI);  
    diff = (newAngle - old);

});

image.addEventListener('touchmove', function(e){

      var conv = e.source.convertPointToView({x: e.x, y:e.y}, win);

      var newAngle = Math.atan2(conv.y - 500, 380 - conv.x)* -(180 / Math.PI);
      current = (newAngle-diff); 
      var t = Ti.UI.create2DMatrix().rotate(current);
      wheel.transform = t;

});
4

1 回答 1

0

你必须设置动画/视图锚点,在 iOS 上你必须设置Ti.UI.View 的 anchorPoint,在 Android 上你必须设置Ti.UI.Animation 的锚点,或者在你的情况下,因为你使用矩阵,只需设置创建时矩阵的锚点(适用于 Android)。

这是您为iOS所做的:

/* iOS */
var image = Titanium.UI.createImageView({
    backgroundImage:'test.png',
    width: 650,
    height: 650,
    anchorPoint: {0.5, 0.5}, // ANchor point is at the center
});

或者,在Android上:

/* Android */
// Matrix, inside your event listener
image.addEventListener('touchmove', function(e){

    var conv = e.source.convertPointToView({x: e.x, y:e.y}, win);

    var newAngle = Math.atan2(conv.y - 500, 380 - conv.x)* -(180 / Math.PI);
    current = (newAngle-diff); 

    // Note that I set the anchor point here.
    var t = Ti.UI.create2DMatrix({anchorPoint: {0.5, 0.5}}).rotate(current);
    wheel.transform = t;
});
于 2013-07-23T15:36:52.320 回答