Question

The matter is, I'm making a drag and drop iPad game. Moving my view like that

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    CGPoint pt = [[touches anyObject] locationInView:self.superview];
    self.center = CGPointMake(pt.x - _xOffset, pt.y - _yOffset);
}

But in some moment I want to stop dragging my view and put it to some location. I'm stuck on how to do that.

Was it helpful?

Solution

You could try to disable the touch handling when you go to position the view finally. Probably the easiest thing to do it to add an instance variable (like BOOL draggingEnabled) which you use to choose how to handle the user interaction. Set the flag to YES when you start a new touch and to NO when you move to the final position. Check the value in touchesMoved before you change the view center.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top