gpt4 book ai didi

appcelerator - 触摸并按住后禁用点击事件

转载 作者:行者123 更新时间:2023-12-02 02:22:46 26 4
gpt4 key购买 nike

我正在 appcelerator 中开发一个应用程序 iOS 应用程序,我得到了一张用户表。当我点击用户时,它会打开个人资料,但我也希望用户能够通过点击并按住 2 秒钟来复制名称。

这两个事件单独工作正常,但现在点击并按住点击事件触发。如何防止点击事件在点按后触发?

// Set the timeout

var holdTime = 500, timeout;

// Create the table touch start event listener

table.addEventListener('touchstart', function(e) {

// Set the selected user id

var itemValue = e.row.value_full;

// Define the function

timeout = setTimeout(function(e) {

// Create the fade out animation

var fadeOut = Titanium.UI.createAnimation({

curve: Ti.UI.ANIMATION_CURVE_EASE_IN_OUT,
opacity: 0,
duration: 1000

});

// Create the loading screen

var copied = UI_messages.showFlash({label : 'Copied!'});

// Add the loading screen

win.add(copied);

// Save value to clipboard

Titanium.UI.Clipboard.setText(itemValue);

// Fade the message out

copied.animate(fadeOut);

}, holdTime);

});

// Create the event listener for touch move

table.addEventListener('touchmove', function() {

// Clear the timeout

clearTimeout(timeout);

});

// Create the event listener for touch move

table.addEventListener('touchend', function(e) {

// Clear the timeout

clearTimeout(timeout);

});

最佳答案

我以前也遇到过这个问题。我使用的解决方案不是很漂亮,但这是我发现在触摸并按住后抑制触摸事件的唯一有效方法。

我能找到的唯一可行的解​​决方案是在全局命名空间中创建一个 bool 变量。在您的 setTimeout 函数中,将 bool 的值更改为 true 以指示发生了触摸并按住。

在该行的 onClick 事件事件中,首先检查全局变量以查看您是否已经创建了一个触摸并按住事件 - 如果有,只需从 onClick 事件。当发生触摸并按住时,这将有效地禁用您的点击事件。

记得在长按功能结束后将全局变量设置为false

关于appcelerator - 触摸并按住后禁用点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7381431/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com