Created
November 6, 2015 01:47
-
-
Save eoghain/b6434f372115924a1757 to your computer and use it in GitHub Desktop.
Countdown ViewController - example of simple countdown view
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 characters
// | |
// ViewController.m | |
// countdown | |
#import "ViewController.h" | |
@interface ViewController () | |
@property (strong, nonatomic) IBOutlet UIView *container; | |
@property (strong, nonatomic) IBOutlet UILabel *label1; | |
@property (strong, nonatomic) IBOutlet UILabel *label2; | |
@property (assign) NSInteger counter; | |
@property (assign) CGRect topFrame; | |
@property (assign) CGRect inFrame; | |
@property (assign) CGRect bottomFrame; | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.counter = 100; | |
self.topFrame = CGRectMake(0, -240, 240, 240); | |
self.inFrame = CGRectMake(0, 0, 240, 240); | |
self.bottomFrame = CGRectMake(0, 240, 240, 240); | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (void)viewDidAppear:(BOOL)animated | |
{ | |
[super viewDidAppear:animated]; | |
[self setValues]; | |
} | |
- (void)setValues | |
{ | |
self.counter--; | |
if (self.counter == 0) | |
{ | |
self.counter = 99; | |
} | |
self.label1.text = [NSString stringWithFormat:@"%2ld", self.counter]; | |
self.label1.frame = self.inFrame; | |
self.label2.text = [NSString stringWithFormat:@"%2ld", self.counter - 1]; | |
self.label2.frame = self.topFrame; | |
[self animate]; | |
} | |
- (void)animate | |
{ | |
[UIView animateWithDuration:1.0 delay:0.1 usingSpringWithDamping:2.0 initialSpringVelocity:2.0 options:0 animations:^{ | |
self.label1.frame = self.bottomFrame; | |
self.label2.frame = self.inFrame; | |
} completion:^(BOOL finished) { | |
[self setValues]; | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment