Skip to content

Instantly share code, notes, and snippets.

@eoghain
Created November 6, 2015 01:47
Show Gist options
  • Save eoghain/b6434f372115924a1757 to your computer and use it in GitHub Desktop.
Save eoghain/b6434f372115924a1757 to your computer and use it in GitHub Desktop.
Countdown ViewController - example of simple countdown view
//
// 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