Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
sample project for touch and gesture
Objective-C
Branch: master

updated

latest commit 649774ee97
@weed authored
Failed to load latest commit information.
TouchAndGesture.xcodeproj updated
TouchAndGesture updated
readme.md updated

readme.md

At first, drag and drop the Swipe Gesture Recognizer from Libraries into View.

ss

And you check off the item canceled in View.

ss

Write code to respond swipe gesture.

- (IBAction)swipe:(id)sender {
    v.backgroundColor = [UIColor blueColor];
}

Then, write touch delegate method.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];    
    CGPoint pt = [touch locationInView:self];
    layer.frame = CGRectMake(pt.x, pt.y, 100, 100);
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];    
    CGPoint pt = [touch locationInView:self];
    layer.frame = CGRectMake(pt.x, pt.y, 100, 100);
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    layer.frame = CGRectMake(0, 0, 100, 100);
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    self.backgroundColor = [UIColor redColor];
}

Now you can move image without cancelled, and you can swipe the screen to set color blue (Swipe Gesture is successfully recognized). Both you can. And, when touch ends, the window color changes to red.

ss

Something went wrong with that request. Please try again.