我创造了一个带有标签的旋转轮。现在,当车轮旋转时,我希望文本在车轮旋转时滑入并滑出标签。
我该怎么做?
我使用以下作为入门代码,并且包含了名为formLabel的标签,其中需要显示幻灯片放入/滑出文本。
代码来自:http://developer.appcelerator.com/question/148344/rotate-image-with-a-single-finger-like-a-disk
var win = Titanium.UI.createWindow({});
var formLabel = Ti.UI.createLabel({
backgroundColor:'none',
text : "",
width : 100,
height : 30,
top:150,
left:350,
align:'center'
})
win.add(formLabel);
var wheel = Titanium.UI.createView({
backgroundImage:'wheel.png',
width:280,height:282
})
var old = 0;
var diff = 0;
var current = 0;
wheel.addEventListener('touchstart', function(e){
var conv = e.source.convertPointToView({x: e.x, y:e.y}, win);
var newAngle = Math.atan2(conv.y - 228, 158 - conv.x)* -(180 / Math.PI);
//where 228 is the centerY of the wheel and 158 is the centerX of the wheel
diff = (newAngle - old);
})
wheel.addEventListener('touchmove', function(e){
var conv = e.source.convertPointToView({x: e.x, y:e.y}, win);
var newAngle = Math.atan2(conv.y - 228, 158 - conv.x)* -(180 / Math.PI);
//where 228 is the centerY of the wheel and 158 is the centerX of the wheel
current = (newAngle-diff);
var t = Ti.UI.create2DMatrix().rotate(current);
wheel.transform = t;
})
wheel.addEventListener('touchend', function(e){
old = current;
})
win.add(wheel);
win.open();