2014-10-07 97 views
1

我想要构建一个可将图片旋转90度的钛应用程序。我的视图显示了imageView和我想用来旋转按钮的按钮。但我总是得到'未定义'的错误。见我的代码和日志如下:将图片旋转90°

var image; 
var imageSet = false; 

var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "savedChallengeImage.jpeg"); 
if(file) { 
    $.picture.setImage(file); 
    image = file; 
    imageSet = true; 
} 

function rotate() { 
    if (imageSet) { 
     var t = Titanium.UI.create2DMatrix(); 
     var spin = Titanium.UI.createAnimation(); 
     t = t.rotate(90); 
     spin.transform = t; 
     file.animate(spin); 
    } 
} 

编辑:我已经修改了文件对象的图像对象,但它以同样的方式表现。我是否正确地获取图像对象?

image = $.picture.getImage(); 
image.animate(spin); 

而且我的日志:

[ERROR] : Script Error { 
[ERROR] :  backtrace = "#0() at :0"; 
[ERROR] :  line = 17; 
[ERROR] :  message = "'undefined' is not a function (evaluating 'file.animate(spin)')"; 
[ERROR] :  name = TypeError; 
[ERROR] :  sourceId = 319168864; 
[ERROR] :  sourceURL = "file:///Users/rellerkmann/Library/Developer/CoreSimulator/Devices/97B059B3-D010-402B-834F-E2647DC8BBC9/data/Containers/Bundle/Application/BB7A6057-D27E-4AB3-92AB-051BE30087BE/RegApp.app/alloy/controllers/challengePicturePage.js"; 
[ERROR] : } 

回答

1

根据该文件,文件对象不具有动画的方法。你将不得不使用ImageView对象。

File

ImageView

您还可以在这里以供参考: https://developer.appcelerator.com/question/84171/rotate-an-image-around-its-center

+0

这种变化并没有改善的事情。请看看我更新的问题。 – 2014-10-07 13:49:05

+0

当您使用getImage()时,您将再次返回一个File对象。你有没有试过$ .picture.animate? – STT 2014-10-07 14:17:19

+0

谢谢你,这个伎俩。 – 2014-10-07 14:23:53