我想根据当前触摸的数量来改变UIView的颜色。我设法通过一次触摸创建了这个:
public static void main(String[] args) {
char[] A = "hello".toCharArray();
char[] B = "hallo".toCharArray();
int ld = LD(A, B, A.length, B.length);
System.out.println(ld);
}
public static int LD(char[] A, char[] B, int n, int m) {
if (n == 0 && m == 0) return 0;
if (n == 0) return m;
if (m == 0) return n;
return min(
LD(A, B, n - 1, m - 1) + A[n - 1] == B[m - 1] ? 0 : 1,
LD(A, B, n, m - 1) + 1,
LD(A, B, n - 1, m) + 1
);
}
private static int min(int a, int b, int c) {
return Math.min(a, Math.min(b, c));
}
但我正在努力实现多点触控。我觉得我在这里不懂东西。
UIView是否有属性来检查当前有多少手指正在接触它?
我可以检查每次新的touchesBegan或touchesEnded发生。
答案 0 :(得分:4)
首先在您的子类上启用多点触控
self.isMultipleTouchEnabled = true
然后在触摸事件功能中,您可以通过UIView类中的事件获得所有触摸。
let touchCount = event?.touches(for: self)?.count
答案 1 :(得分:1)
确保var hasKeywords = false,
hasExclusions = false;
options.forEach(function(singleOption){
// if at least (!) one option is found in the text you can definitely state the text contains keyword
if (text.indexOf(singleOption) >= 0) { hasKeywords = true}
});
exclusions.forEach(function(element){
// if at least on exclusion is found in the text you can say for sure that forbidden words are present
if (text.indexOf(element) >= 0) { hasExclusions = true}
});
if (hasKeywords && !hasExclusions) {
// do whatever you want
}
有UIView
,默认为isMultipleTouchEnabled = true
。
然后更改false
方法
touchesBegan