我也遇到了这个问题。
根本原因是 Titanium 在每次点击事件后都会重新分配 backgroundImage 属性,而不管实际属性是否已更改。
要解决此问题,您可以破解处理 backgroundImage 更新的 Element.js 文件。
可以在两个地方之一应用编辑(仅在 Windows 上测试,版本 3.1.3.GA):
%ProjectFolder%\build\mobileweb\titanium\Ti\_\UI\Element.js
在这里,我们正在编辑生成的 JS 文件,这必须在每次构建后完成。如果您不想编辑实际的 Titanium SDK 并且只想修复最终版本,则此选项可能很有用。
C:\%USER FOLDER%\App Data\Roaming\Titanium\mobilesdk\win32\3.1.3.GA\mobileweb\titanium\Ti\_\UI\Element.js
如果您编辑此文件,您实际上是在更改 Titanium SDK。当您升级到新的 SDK 版本时,您只需重复此编辑。
选择您的文件,然后从第 534 行开始应用此编辑:
改变:
bi = style.url(bi);
nodeStyle.backgroundImage.replace(/'|"/g, '').toLowerCase() !== bi.toLowerCase() &&(nodeStyle.backgroundImage = bi);
至:
bi = style.url(bi);
var currentB = nodeStyle.backgroundImage;
var ind=currentB.lastIndexOf("/");
var ind2= bi.lastIndexOf("/");
if(nodeStyle.backgroundImage.substr(ind) !== bi.substr(ind2))
{
nodeStyle.backgroundImage.replace(/'|"/g, '').toLowerCase() !== bi.toLowerCase() && (nodeStyle.backgroundImage = bi);
}
此修复导致 Titanium 仅在背景图像的文件名更改时重置 backgroundImage 属性。请注意,此代码仅检查文件名是否更改,而不是路径,因此如果这对您很重要,请相应地调整您的代码。
此编辑也适用于 SDK 版本:3.2.0 GA。