如何在容器列表中检测到“缩小”? [英] How to detect a 'pinch out' in a list of containers?

查看:70
本文介绍了如何在容器列表中检测到“缩小”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将容器列表中的两个容器彼此分开,以在它们之间插入一个新的空容器。与iPhone应用程序清除插入新任务的方式类似(例如,请参见本页上的第一张图片 https://www.raywenderlich.com/22174/how-to-make-a-gesture驱动待办事项清单- app-part-33 -当两个环绕容器相互挤压时,将插入红色的小容器)。关于如何在Codename One中实现此目标的任何提示?

I want to be able to pinch two containers in a list of containers away from each other to insert a new empty container between them. Similar to how the iPhone app "Clear" inserts new tasks (see for example the very first picture on this page https://www.raywenderlich.com/22174/how-to-make-a-gesture-driven-to-do-list-app-part-33 - the small red container is inserted when the two sorounding containers are pinched away from each other). Any hints on how I can achieve this in Codename One?

推荐答案

通常,您会覆盖 pinch 方法,以实现缩放或类似调用。但是,在这种情况下,这是行不通的,因为夹点将超出组件边界,并且行不通。

Normally you would override the pinch method to implement pinch to zoom or similar calls. However, this won't work in this case as the pinch will exceed component boundaries and it wouldn't work.

我唯一想到的方法是覆盖 Form 中的 pointerDragged(int [],int [])方法,并检测捏动动作的实现这个。您可以在 Component.java 中查看捏合代码,因为这样做应该是一个很好的基础:

The only way I can think of doing this is to override the pointerDragged(int[],int[]) method in Form and detect the pinch motion as growing to implement this. You can check out the code for pinch in Component.java as it should be a good base for this:

public void pointerDragged(int[] x, int[] y) {
    if (x.length > 1) {
        double currentDis = distance(x, y);

        // prevent division by 0
        if (pinchDistance <= 0) {
            pinchDistance = currentDis;
        }
        double scale = currentDis / pinchDistance;
        if (pinch((float)scale)) {
            return;
        }
    }
    pointerDragged(x[0], y[0]);
}
private double distance(int[] x, int[] y) {
    int disx = x[0] - x[1];
    int disy = y[0] - y[1];
    return Math.sqrt(disx * disx + disy * disy);
}

添加条目很简单,只需将空白组件放在该位置并成长它的首选大小,直到达到所需大小为止。

Adding the entry is simple, just place a blank component in the place and grow its preferred size until it reaches the desired size.

这篇关于如何在容器列表中检测到“缩小”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆