Rotate an image around its center
The following code should rotate an image around it's center. I haven't tried it on iPhone. But on Android, it rotates around the upper-left corner of the image instead. Anyone have an idea on how to make it rotate around the image's middle?
// Just past me into into a blank app.js file and run
window = Titanium.UI.createWindow({
backgroundColor:'#47a',
exitOnClose: true
});
//load test image from the appcelerator web site
var image = Titanium.UI.createImageView({
image:'default_app_logo.png',
backgroundColor:'transparent',
canScale:false,
anchorPoint:{x:0.5,y:0.5},
height:'200',
width:'200'
});
// Spin the image
var t = Ti.UI.create2DMatrix();
var spin = Titanium.UI.createAnimation();
t = t.rotate(30);
spin.transform = t;
spin.duration = 50;
window.add(image);
image.animate(spin);
window.open({fullscreen:true});
3 Answers
-
I know it's Too late for answering this question but still i give it for make community strong..
This is the code that works in both
// Just past me into into a blank app.js file and run var win = Titanium.UI.createWindow({ backgroundColor : 'white', }); //load test image from the appcelerator web site var img = Titanium.UI.createImageView({ image : 'wheel.2.png', backgroundColor : 'transparent', anchorPoint : { x : 0.5, y : 0.5 }, height : 100, width : 100 }); // Spin the image var matrix2d = Ti.UI.create2DMatrix(); matrix2d = matrix2d.rotate(180); // in degrees // matrix2d = matrix2d.scale(1.5); // scale to 1.5 times original size var a = Ti.UI.createAnimation({ transform: matrix2d, duration: 1000, autoreverse: true, repeat: 3 }); win.add(img); img.animate(a); win.open({ fullscreen : true });
-
anchorPoint:{x:0.5, y:0.5}
I think the values here are measured in pixels. Try:
anchorPoint:{x:100, y:100}
-
this a question i have seen on other forum and i fianlly get the codes to rotate images vb.net around the center. thank you .