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

标签 appcelerator

我正在 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/

相关文章:

php - 无法将大于 500kb 的视频文件大小上传到 Android 中的 Linux 服务器

Titanium 桌面中的 SVG?

android - Appcelerator - Android 上的音频格式

javascript - 获取存储在 Ti.Filesystem appcelerator 中的图像

ios - 在 Appcelerator Titanium 应用程序中打开另一个窗口不起作用

android - 如何解决 Titanium 错误 "Ex...tion: No Android ' - 8' or android ' -2。运行 OSX Lion 的 Mac 上的 2' in the Android SDK."?

javascript - Titanium 中的内容和数据调用密集型应用程序

javascript - Appcelerator Titanium 或 JavaScript 的源代码审查和分析工具?

javascript - Titanium Appcelerator 使用 API 解析 Youtube JSON

ios - 如何在 Appcelerator 中对按钮/图像产生压抑效果