Skip to content

Instantly share code, notes, and snippets.

@drart
Forked from C4Tutorials/C4WorkSpace.m
Created June 2, 2013 13:54
Show Gist options
  • Save drart/5693723 to your computer and use it in GitHub Desktop.
Save drart/5693723 to your computer and use it in GitHub Desktop.
//
// C4WorkSpace.m
// Swipes Tutorial
//
// Created by Travis Kirton.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Label *swipeDirection;
C4Timer *resetTimer;
}
-(void)setup {
C4Font *font = [C4Font fontWithName:@"Helvetica" size:96];
swipeDirection = [C4Label labelWithText:@"Swipe Me" font:font];
[swipeDirection sizeToFit];
swipeDirection.textAlignment = ALIGNTEXTCENTER;
swipeDirection.center = self.canvas.center;
swipeDirection.userInteractionEnabled = NO;
[self.canvas addLabel:swipeDirection];
[self addGesture:SWIPEDOWN name:@"down" action:@"swipedDown"];
[self addGesture:SWIPELEFT name:@"left" action:@"swipedLeft"];
[self addGesture:SWIPERIGHT name:@"right" action:@"swipedRight"];
[self addGesture:SWIPEUP name:@"up" action:@"swipedUp"];
}
-(void)swipedDown {
[self updateLabelWithText:@"DOWN"];
}
-(void)swipedLeft {
[self updateLabelWithText:@"LEFT"];
}
-(void)swipedRight {
[self updateLabelWithText:@"RIGHT"];
}
-(void)swipedUp {
[self updateLabelWithText:@"UP"];
}
-(void)resetLabel {
swipeDirection.text = @"Swipe Me";
[swipeDirection sizeToFit];
swipeDirection.center = self.canvas.center;
}
-(void)updateLabelWithText:(NSString *)newLabelText {
swipeDirection.text = newLabelText;
[swipeDirection sizeToFit];
swipeDirection.center = self.canvas.center;
[resetTimer invalidate];
resetTimer = [C4Timer automaticTimerWithInterval:2.0f target:self method:@"resetLabel" repeats:NO];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment