I have a custom UIView that generates a set of subzones and displays them in rows and columns, such as tiles. What I'm trying to achieve is to let the user touch the screen, and when the finger moves, the tiles under it disappear.
Below is the UIView code that contains the fragments:
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
int i, j;
int maxCol = floor(self.frame.size.width/TILE_SPACING);
int maxRow = floor(self.frame.size.height/TILE_SPACING);
CGRect frame = CGRectMake(0, 0, TILE_WIDTH, TILE_HEIGHT);
UIView *tile;
for (i = 0; i<maxCol; i++) {
for (j = 0; j < maxRow; j++) {
frame.origin.x = i * (TILE_SPACING) + TILE_PADDING;
frame.origin.y = j * (TILE_SPACING) + TILE_PADDING;
tile = [[UIView alloc] initWithFrame:frame];
[self addSubview:tile];
[tile release];
}
}
}
return self;
}
- (void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event {
UIView *tile = [self hitTest:[[touches anyObject] locationInView:self] withEvent:nil];
if (tile != self)
[tile setHidden:YES];
}
- (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event {
UIView *tile = [self hitTest:[[touches anyObject] locationInView:self] withEvent:nil];
if (tile != self)
[tile setHidden:YES];
}
This approach works, but if the tiles become denser (i.e. smaller tiles and more tiles on the screen). The iPhone is less sensitive as it moves with a finger. It could be hitTest, charging for the processor, as it struggles to keep up, but would like some opinions.
My questions:
Is this an efficient way / right way to implement touchphonesMoved?
If not, what would be the recommended approach?
Tile ( UIView), . subview Tile TouchesBegan, TouchesBegan , . subview Tile, TouchesBegan/TouchesMoved ?