Этот код является идеей о том, как получить затронутые прямоугольники.Для каждого нового прикосновенного прямоугольника будет добавлен счетчик 1, так что будет легче отслеживать движение касания (при необходимости).Для большей точности измените значения для констант ROWS и COLS
#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.
}
Он должен быть размещен на контроллере вида, вид которого вы хотите определить форму касания.