Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "ViewController.h"
- @interface ViewController ()
- {
- CGFloat windowWidth;
- CGFloat initialDelay;
- CGFloat stutter;
- CGSize size;
- }
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
- windowWidth = self.window.bounds.size.width;
- initialDelay= 1.0f;
- stutter = 0.06f;
- [self firstRow];
- [self secondRow];
- self.window.backgroundColor = [UIColor whiteColor];
- [self.window makeKeyAndVisible];
- }
- -(void)firstRow{
- UIImageView * row = [[UIImageView alloc]initWithFrame:CGRectMake(windowWidth, 170, windowWidth, 80)];
- row.image = [UIImage imageNamed:@"1st-row"];
- UIImage * returnedImage = [self drawText:@"12:00" inImage:row.image atPoint:CGPointMake(0, 10)];
- UIImageView * finalImage = [[UIImageView alloc]initWithImage:returnedImage];
- [self.window addSubview:finalImage];
- [UIView animateWithDuration:2.1 delay:initialDelay + (3 * stutter) usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
- [finalImage setFrame:CGRectMake(0, 170, windowWidth, 80)];
- } completion:NULL];
- }
- -(void)secondRow{
- UIImageView *secondRow = [[UIImageView alloc] initWithFrame:CGRectMake(windowWidth*1.5, 170+80, windowWidth, 80)];
- secondRow.image = [UIImage imageNamed:@"1st-row"];
- UIImage * secondImage = [self drawText:@"12:00" inImage:secondRow.image atPoint:CGPointMake(0, 10)];
- UIImageView * secondFinalImage = [[UIImageView alloc]initWithImage:secondImage];
- secondFinalImage.alpha = 0.0f;
- [self.window addSubview:secondFinalImage];
- [UIView animateWithDuration:2.0 delay:initialDelay + (4 * stutter) usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
- [secondFinalImage setFrame:CGRectMake(0, 170+70, windowWidth, 80)];
- secondFinalImage.alpha = 1.0f;
- } completion:NULL];
- }
- -(UIImage *)drawText:(NSString *)text
- inImage:(UIImage *) image
- atPoint:(CGPoint) point{
- UIFont *font = [UIFont boldSystemFontOfSize:40];
- UIGraphicsBeginImageContext(image.size);
- [image drawAtPoint:point];
- CGRect rect = CGRectMake(point.x, point.y, image.size.width, image.size.height);
- [[UIColor redColor] set];
- [text drawInRect:CGRectIntegral(rect) withFont:font];
- image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return image;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement