Titanium 钛合金应用程序在iOS上拍照时冻结
环境:iOS 7.0.3和6.1.3,在iPhone设备(几个单独的设备)上测试。Ti v 3.1.3和合金1.2.2 在设备上拍照时,我的应用程序无法冻结。从图库中选择一张照片没有问题,但是当拍摄照片时,应用程序在移动和缩放屏幕上冻结——似乎是在点击“使用”按钮之后。我的代码如下:Titanium 钛合金应用程序在iOS上拍照时冻结,titanium,titanium-alloy,Titanium,Titanium Alloy,环境:iOS 7.0.3和6.1.3,在iPhone设备(几个单独的设备)上测试。Ti v 3.1.3和合金1.2.2 在设备上拍照时,我的应用程序无法冻结。从图库中选择一张照片没有问题,但是当拍摄照片时,应用程序在移动和缩放屏幕上冻结——似乎是在点击“使用”按钮之后。我的代码如下: $.avatar.addEventListener("click", function() { var opts = { cancel : 2, options : ['T
$.avatar.addEventListener("click", function() {
var opts = {
cancel : 2,
options : ['Take a Photo', 'Select from Gallery', 'Cancel'],
selectedIndex : 2,
destructive : 0,
title : 'Set a Profile Photo:'
};
var dialog = Ti.UI.createOptionDialog(opts);
dialog.show();
dialog.addEventListener("click", function(e) {
switch(e.index) {
case(0):
Titanium.Media.showCamera({
allowEditing : true,
success : function(event) {
$.avatar.status = "new";
$.avatar.image = event.media;
},
error : function(event) {
console.log(event);
}
});
case(1):
Titanium.Media.openPhotoGallery({
allowEditing : true,
success : function(event) {
$.avatar.status = "new";
$.avatar.image = event.media;
},
error : function(event) {
console.log(event);
}
});
}
});
});
这里所期望的行为是用户点击他们的化身,打开选项菜单。然后他们点击“拍照”,打开相机,让他们拍照并裁剪。点击“使用”后,该照片将显示在$.avatar ImageView中
我已经能够在我测试过的每台设备上,跨多个iOS版本复制这一点。这是合金或钛的缺陷,还是我在这里做了一些明显错误的事情?
谢谢 我也在做同样的事情,我这里有代码片段,希望它能帮助您:
var options = {
success: function(e) {
// var tempDate = new Date().getTime();
var completeSubfix = rcvImage.subfix + APP.uniqueIdCounter(sectionId);
var noDashPlatformId = Titanium.Platform.id.replace(/-/g,"");
var imageName = result[0].parentAccount + "-" +result[0].id_user + "-" + noDashPlatformId + "-" + completeSubfix;
urls[rcvImage.id] = Ti.Filesystem.applicationDataDirectory+ imageName+ '.png';
var tmpPhoto = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, imageName + '.png');
tmpPhoto.write(e.media);
var useHeight = true;
if(OS_ANDROID){
//If in portrait, we use this variable to invert the cropping.
useHeight = e.cropRect.height < e.cropRect.width ? true : false;
}
//Creating thumbnail for both OS
var thumbnailtmp = e.media.imageAsThumbnail(180, 1,2);
if(OS_ANDROID){
//Making it a rectangle again so it wont get streched on the image view
thumbnailtmp = thumbnailtmp.imageAsCropped({
width: useHeight ? 180 : 122,
height: useHeight ? 122 : 180,
x:0,
y:0
});
}
//
var thumbnail = Ti.UI.createImageView({
image: thumbnailtmp
});
var tmpPhoto = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, imageName + '_thum.png');
tmpPhoto.write(thumbnail.image);
rcvImage.image = tmpPhoto.nativePath;
//rcvImage.image = APP.getThumbnailMedium(urls[rcvImage.id] ,"medium");
if(OS_IOS){
rcvImage.children[0].opacity = 0.6;
rcvImage.children[1].text = completeSubfix;
}
else{
rcvImage.parent.children[1].opacity = 0.6;
rcvImage.parent.children[2].text = completeSubfix;
}
_callback(rcvImage);
},
cancel:function() {
// called when user cancels taking a picture
},
error:function(error) {
// called when there's an error
var a = Titanium.UI.createAlertDialog({title:'Camera'});
if (error.code == Titanium.Media.NO_CAMERA) {
a.setMessage('Please run this test on device');
} else {
a.setMessage('Unexpected error: ' + error.code);
}
a.show();
},
};
Ti.Media.showCamera(options);
var选项={
成功:职能(e){
//var tempDate=new Date().getTime();
var completeSubfix=rcvImage.subfix+APP.uniqueIdCounter(sectionId);
变量noDashPlatformId=钛.平台id.替换(/-/g,“”);
var imageName=result[0]。parentAccount+“-”+result[0]。id_user+“-”+noDashPlatformId+“-”+completeSubfix;
URL[rcvImage.id]=Ti.Filesystem.applicationDataDirectory+imageName+'.png';
var tmpPhoto=Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,imageName+'.png');
tmpPhoto.write(e.media);
var usehight=true;
如果(OS_ANDROID){
//如果在纵向中,我们使用此变量反转裁剪。
useHeight=e.cropRect.height
这个问题的答案非常简单,而且非常简单。我忘了包括中断
在每个案例的末尾,使switch语句在拍照时在这两个案例中运行。加上这一点,解决了这个问题
-1表示n00b级错误