J'essaie de déplacer un UIView par rapport aux touches de l'utilisateur.Déplacer UIView par rapport au toucher
Voici ce que j'ai en ce moment:
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 vue continue vacillante d'un endroit à l'autre, et je ne sais pas quoi faire d'autre.
Toute aide appréciée.
fenêtre est l'objet que vous faites glisser? – EmptyStack
Oui, il s'agit d'une vue créée dans Interface Builder. –
C'est beaucoup mieux, mais bizarrement zoom sur le côté chaque fois qu'il est touché. –