Last active
December 16, 2015 10:39
-
-
Save C4Tutorials/5421765 to your computer and use it in GitHub Desktop.
Swipes Tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// C4WorkSpace.m | |
// Swipes Tutorial | |
// | |
// Created by Travis Kirton. | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
NSDictionary *allGestures; | |
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