Last active
August 29, 2015 13:57
Revisions
-
seanwoodward revised this gist
Mar 14, 2014 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -61,7 +61,12 @@ - (IBAction)addNumber:(id)sender - (IBAction)longPress:(id)sender { UILongPressGestureRecognizer *gr = (UILongPressGestureRecognizer *)sender; CGPoint touchLocation = [gr locationInView:self.view]; BOOL touchInButton = CGRectContainsPoint(gr.view.frame, touchLocation); if (!self.numberTimer && touchInButton) { self.cancelTimer = NO; [self addNumber:nil]; } -
seanwoodward revised this gist
Mar 14, 2014 . 1 changed file with 26 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,12 @@ @interface ViewController @property (nonatomic, assign) NSTimeInterval timeInterval; - (void)updateNumberLabel; - (void)stopTimer; - (IBAction)longPress:(id)sender; - (IBAction)touchUpInside:(id)sender; - (IBAction)touchDragExit:(id)sender; - (IBAction)touchCancel:(id)sender; @end @@ -20,10 +23,15 @@ - (void)updateNumberLabel self.numberLabel.text = [NSString stringWithFormat:@"%d", [@(self.value) intValue]]; } - (void)stopTimer { self.cancelTimer = YES; if (self.numberTimer) { [self.numberTimer invalidate]; self.numberTimer = nil; self.timeInterval = 0; } [self updateNumberLabel]; } @@ -36,7 +44,7 @@ - (IBAction)addNumber:(id)sender } if (self.cancelTimer) { [self stopTimer]; return; } @@ -51,18 +59,26 @@ - (IBAction)addNumber:(id)sender self.numberTimer = timer; } - (IBAction)longPress:(id)sender { if (!self.numberTimer) { self.cancelTimer = NO; [self addNumber:nil]; } } - (IBAction)touchUpInside:(id)sender { [self stopTimer]; } - (IBAction)touchDragExit:(id)sender { [self stopTimer]; } - (IBAction)touchCancel:(id)sender { [self stopTimer]; } @end -
seanwoodward revised this gist
Mar 14, 2014 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,7 @@ @interface ViewController - (void)updateNumberLabel; - (IBAction)touchUpInside:(id)sender; - (IBAction)longPress:(id)sender; - (IBAction)touchDragExit:(id)sender; @end @@ -56,4 +57,12 @@ - (IBAction)longPress:(id)sender { [self addNumber:nil]; } } - (IBAction)touchDragExit:(id)sender { self.cancelTimer = YES; if (self.numberTimer) { [self.numberTimer invalidate]; } } @end -
seanwoodward created this gist
Mar 14, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ @interface ViewController @property (nonatomic, weak) IBOutlet UILabel *numberLabel; @property (nonatomic, strong) NSTimer *numberTimer; @property (nonatomic, assign) double value; @property (nonatomic, assign) BOOL cancelTimer; @property (nonatomic, assign) NSTimeInterval timeInterval; - (void)updateNumberLabel; - (IBAction)touchUpInside:(id)sender; - (IBAction)longPress:(id)sender; @end @implementation ViewController - (void)updateNumberLabel { self.numberLabel.text = [NSString stringWithFormat:@"%d", [@(self.value) intValue]]; } - (IBAction)touchUpInside:(id)sender { self.cancelTimer = YES; self.timeInterval = 0; [self updateNumberLabel]; } - (IBAction)addNumber:(id)sender { NSTimeInterval newInterval = self.timeInterval ?: 1; if (self.numberTimer) { newInterval = MAX(0.02, newInterval - newInterval * 0.2); } if (self.cancelTimer) { self.numberTimer = nil; return; } self.value += 1; [self updateNumberLabel]; self.timeInterval = newInterval; NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:newInterval target:self selector:@selector(addNumber:) userInfo:nil repeats:NO]; self.numberTimer = timer; } - (IBAction)longPress:(id)sender { if (!self.numberTimer) { self.cancelTimer = NO; [self addNumber:nil]; } } @end