Estoy tratando de mover una UIView en relación con los toques del usuario.Mover UIView con relación al tacto
Esto es lo que tengo en este momento:
int oldX, oldY;
BOOL dragging;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(window.frame, touchLocation)) {
dragging = YES;
oldX = touchLocation.x;
oldY = touchLocation.y;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(window.frame, touchLocation) && dragging) {
CGRect frame;
frame.origin.x = (window.frame.origin.x + touchLocation.x - oldX);
frame.origin.y = (window.frame.origin.y + touchLocation.y - oldY);
window.frame = frame;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
dragging = NO;
}
La vista mantiene el parpadeo de un lugar a otro, y no sé qué más hacer.
Cualquier ayuda apreciada.
¿ventana es el objeto que está arrastrando? – EmptyStack
Sí, es una vista creada en Interface Builder. –
Es mucho mejor, pero extrañamente se aleja cuando se toca. –