Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iphone或android上检测触摸形状?_Android_Ios_Touch - Fatal编程技术网

在iphone或android上检测触摸形状?

在iphone或android上检测触摸形状?,android,ios,touch,Android,Ios,Touch,是否有一个公共或私有的API可以让应用程序获得被触及的表面?我对Android和/或iOS感兴趣 换句话说,我对触摸屏幕的手指的形状感兴趣 一个可以返回一个接触矩形矩阵的解决方案也可以 (我90%肯定没有这样的事情,但我希望有人能证明我错了)这段代码是关于如何获得触摸矩形的想法。对于每个新触摸的矩形,将添加一个计数器1,以便更容易跟踪触摸移动(如果需要)。为了更精确,请更改常量行和列的值 #define ROWS 15 #define COLS ROWS int matrix[ROWS][CO

是否有一个公共或私有的API可以让应用程序获得被触及的表面?我对Android和/或iOS感兴趣

换句话说,我对触摸屏幕的手指的形状感兴趣

一个可以返回一个接触矩形矩阵的解决方案也可以


(我90%肯定没有这样的事情,但我希望有人能证明我错了)

这段代码是关于如何获得触摸矩形的想法。对于每个新触摸的矩形,将添加一个计数器1,以便更容易跟踪触摸移动(如果需要)。为了更精确,请更改常量行和列的值

#define ROWS 15
#define COLS ROWS

int matrix[ROWS][COLS];
int squareCounter;


- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];

    int col = floor((location.x * COLS) / self.view.frame.size.width);
    int row = floor((location.y * ROWS) / self.view.frame.size.height);
    if (matrix[col][row] == 0) matrix [col][row] = ++ squareCounter;

    [label setText:[NSString stringWithFormat:@"[%d][%d] -> %d", col, row, matrix[col][row]]];
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSString *matrixStr = @"";
    for (int i = 0; i < COLS; i++) {
        for (int j = 0; j < ROWS; j++) {
            matrixStr = [matrixStr stringByAppendingFormat:@"%d\t", matrix[j][i]];
        }
        matrixStr = [matrixStr stringByAppendingString:@"\n"];
    }

    NSLog(@"Matrix:\n%@", matrixStr);
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    squareCounter = 0;
    for (int i = 0; i < ROWS; i++) {
        for (int j = 0; j < COLS; j++) {
            matrix[i][j] = 0;
        }
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}
#定义第15行
#定义COLS行
int矩阵[行][COLS];
整数平方计数器;
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint location=[touch locationInView:touch.view];
int col=地板((location.x*COLS)/self.view.frame.size.width);
int row=地板((location.y*行)/self.view.frame.size.height);
如果(矩阵[col][row]==0)矩阵[col][row]=++平方计数器;
[label setText:[NSString stringWithFormat:@“[%d][%d]->%d”,列、行、矩阵[col][row]];
}
-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event{
NSString*matrixStr=@;
for(int i=0;i

它必须放在视图控制器上,您要检测其视图的触摸形状。

我找到了Android的解决方案: . 我仍然需要知道它是如何被支持的

对于iPhone: (见公认答案)。 然而,似乎没有官方的办法

不过,如果有人添加了一些官方或非官方/黑客方法,我将不胜感激。

根据要求回答:

在Android上,我认为您最好使用,它返回手指的大小(而不是形状)。
API演示使用了这一点。

我不知道iOS上有类似的东西。iOS检测到你的手指在哪里,我认为你无法获取原始的传感器信息。除非有人找到了方法,否则我认为这在Android上是不可用的。Android以单像素坐标注册触摸,我认为您必须绕过操作系统进入硬件级别。在Android上,我认为您最好使用MotionEvent.getSize(),它返回手指的大小(而不是形状)@Deev,fishinear:这在两个平台上都是可能的,请看我的答案。。。但我仍然想找到一些其他的方法,黑客,在什么条件下可以做的额外信息。。。我将对任何提供最多附加信息的人给予奖励。@Jave:是否将其作为单独的答案发布?如果我理解正确,iOS只报告触摸中心?所以这个代码沿着手指的中心,并将其路径(而不是形状)保存在矩阵中?就是这样。在iOS中,触摸识别器仅通过触摸发送X和Y。如果你想追踪两个手指,你唯一需要做的就是有一个矩阵,一个手指和触摸矩阵之间的关系,所以如果我想要一个手指的形状,当不移动时,我就走运了?顺便说一句,即使手指覆盖的区域大小也会有帮助。。。Android似乎支持这一点(见我的答案),iOS呢?我认为这是一个和屏幕技术有关的问题。电阻屏可以给出类似于点的矩阵。但电容式屏幕的工作原理是另一种,我严重怀疑你能否得到近似的形状,因为你需要大量的点来定义形状。触摸区域的大致大小对我来说就足够了——这在iOS上可能吗?请注意,Android似乎支持这一点,所以我想这应该是可能的(硬件方面)。谢谢你的帮助,Jave!我在下面的单独答案中发布了一个完整的解决方案(iPhone也是)。