Troubles moving a UIView.

Posted by Joshua on Stack Overflow See other posts from Stack Overflow or by Joshua
Published on 2010-04-16T14:51:32Z Indexed on 2010/04/16 14:53 UTC
Read the original article Hit count: 215

Filed under:
|
|

I have been trying to move a UIView by following a users touch. I have almost got it to work except for one thing, the UIView keeps flicking between two places.

Here's the code I have been using:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchDown");
    UITouch *touch = [touches anyObject];
    firstTouch = [touch locationInView:self.view];
    lastTouch = [touch locationInView:self.view];
    [self.view setNeedsDisplay];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    InSightViewController *contentView = [[InSightViewController alloc] initWithNibName:@"SubView" bundle:[NSBundle mainBundle]];
    [contentView loadView];
    UITouch *touch = [touches anyObject];
    currentTouch = [touch locationInView:self.view];
    if (CGRectContainsPoint(contentView.view.bounds, firstTouch)) {
        NSLog(@"touch in subView/contentView");
        sub.frame = CGRectMake(currentTouch.x - 50.0, currentTouch.y, 130.0, 21.0);
    }
    NSLog(@"touch moved");
    lastTouch = currentTouch;   
    [self.view setNeedsDisplay];
}

And here's what's been happening: http://cl.ly/Sjx

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about objective-c