Skip to content

Instantly share code, notes, and snippets.

@gregtemp
Last active December 14, 2015 12:18
Show Gist options
  • Save gregtemp/5085876 to your computer and use it in GitHub Desktop.
Save gregtemp/5085876 to your computer and use it in GitHub Desktop.
touchesBegan (test example)
//
// C4WorkSpace.m
// Examples
//
// Created by Greg Debicki.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Shape *s1, *s2;
}
-(void)setup {
[self setupShapes];
}
-(void) setupShapes {
CGRect rect = CGRectMake(0, 0, 300, 75);
s1 = [C4Shape rect:rect];
s2 = [C4Shape rect:rect];
CGPoint currentCenter = self.canvas.center;
s1.center = currentCenter;
s2.center = currentCenter;
[self.canvas addShape:s1];
[self.canvas addShape:s2];
s1.animationDuration = 0.5f;
s2.animationDuration = 0.5f;
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchedPoint = [[touches anyObject] locationInView:self.view];
if (touchedPoint.y <= self.canvas.height/2) {
if (touchedPoint.x <= self.canvas.width/2){
s2.rotation += PI/5.0f;
}
if (touchedPoint.x > self.canvas.width/2){
s2.rotation -= PI/5.0f;
}
}
if (touchedPoint.y > self.canvas.height/2) {
if (touchedPoint.x <= self.canvas.width/2){
s1.rotation += PI/5.0f;
}
if (touchedPoint.x > self.canvas.width/2){
s1.rotation -= PI/5.0f;
}
}
}
@end
@C4Code
Copy link

C4Code commented Mar 4, 2013

I would add this:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    self.canvas.userInteractionEnabled = NO;

    CGPoint touchedPoint = [[touches anyObject] locationInView:self.view];

    if (touchedPoint.y <= self.canvas.height/2) {
        if (touchedPoint.x <= self.canvas.width/2){
            s2.rotation += PI/5.0f;
        }
        if (touchedPoint.x > self.canvas.width/2){
            s2.rotation -= PI/5.0f;
        }
        [self runMethod:@"allowInteraction" afterDelay:s2.animationDuration];
    }
    else if (touchedPoint.y > self.canvas.height/2) {
        if (touchedPoint.x <= self.canvas.width/2){
            s1.rotation += PI/5.0f;
        }
        if (touchedPoint.x > self.canvas.width/2){
            s1.rotation -= PI/5.0f;
        }
        [self runMethod:@"allowInteraction" afterDelay:s1.animationDuration];
    }

}

-(void)allowInteraction {
    self.canvas.userInteractionEnabled = YES;
}

... it shuts off user interaction for the duration of the animation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment