Arrastrando un UIView dentro de UIScrollView
Estoy tratando de resolver un problema básico con arrastrar y soltar en iPhone. Aquí está mi configuración:
Tengo un UIScrollView que tiene una subvista de contenido grande (puedo desplazarla y hacer zoom)La subvista de contenido tiene varios mosaicos pequeños como subvistas que deben arrastrarse dentro de ella.Mi subclase UIScrollView tiene este método:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *tile = [contentView pointInsideTiles:[self convertPoint:point toView:contentView] withEvent:event];
if (tile) {
return tile;
} else {
return [super hitTest:point withEvent:event];
}
}
La subvista de contenido tiene este método:
- (UIView *)pointInsideTiles:(CGPoint)point withEvent:(UIEvent *)event {
for (TileView *tile in tiles) {
if ([tile pointInside:[self convertPoint:point toView:tile] withEvent:event])
return tile;
}
return nil;
}
Y la vista de azulejos tiene este método:
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.superview];
self.center = location;
}
Esto funciona, pero no es totalmente correcto: el mosaico a veces se "cae" durante el proceso de arrastre. Más precisamente, deja de recibir toques Movidos: invocaciones, y la vista de desplazamiento comienza a desplazarse en su lugar. Noté que esto depende de la velocidad de arrastre: cuanto más rápido arrastre, más rápido "cae" el mosaico.
¿Alguna idea sobre cómo mantener el azulejo pegado al dedo que arrastra?