Advertisement
Guest User

RowAnimation

a guest
Aug 2nd, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1.  
  2. #import "ViewController.h"
  3.  
  4. @interface ViewController ()
  5. {
  6.  
  7. CGFloat windowWidth;
  8. CGFloat initialDelay;
  9. CGFloat stutter;
  10. CGSize size;
  11.  
  12.  
  13. }
  14.  
  15.  
  16. @end
  17.  
  18. @implementation ViewController
  19.  
  20.  
  21.  
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24.  
  25. self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
  26.  
  27. windowWidth = self.window.bounds.size.width;
  28. initialDelay= 1.0f;
  29. stutter = 0.06f;
  30.  
  31. [self firstRow];
  32. [self secondRow];
  33.  
  34.  
  35. self.window.backgroundColor = [UIColor whiteColor];
  36. [self.window makeKeyAndVisible];
  37.  
  38. }
  39.  
  40. -(void)firstRow{
  41.  
  42. UIImageView * row = [[UIImageView alloc]initWithFrame:CGRectMake(windowWidth, 170, windowWidth, 80)];
  43.  
  44. row.image = [UIImage imageNamed:@"1st-row"];
  45.  
  46. UIImage * returnedImage = [self drawText:@"12:00" inImage:row.image atPoint:CGPointMake(0, 10)];
  47.  
  48. UIImageView * finalImage = [[UIImageView alloc]initWithImage:returnedImage];
  49.  
  50. [self.window addSubview:finalImage];
  51.  
  52.  
  53. [UIView animateWithDuration:2.1 delay:initialDelay + (3 * stutter) usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
  54.  
  55. [finalImage setFrame:CGRectMake(0, 170, windowWidth, 80)];
  56.  
  57. } completion:NULL];
  58.  
  59.  
  60. }
  61.  
  62. -(void)secondRow{
  63.  
  64. UIImageView *secondRow = [[UIImageView alloc] initWithFrame:CGRectMake(windowWidth*1.5, 170+80, windowWidth, 80)];
  65. secondRow.image = [UIImage imageNamed:@"1st-row"];
  66.  
  67.  
  68. UIImage * secondImage = [self drawText:@"12:00" inImage:secondRow.image atPoint:CGPointMake(0, 10)];
  69.  
  70. UIImageView * secondFinalImage = [[UIImageView alloc]initWithImage:secondImage];
  71.  
  72. secondFinalImage.alpha = 0.0f;
  73.  
  74. [self.window addSubview:secondFinalImage];
  75.  
  76. [UIView animateWithDuration:2.0 delay:initialDelay + (4 * stutter) usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
  77. [secondFinalImage setFrame:CGRectMake(0, 170+70, windowWidth, 80)];
  78. secondFinalImage.alpha = 1.0f;
  79. } completion:NULL];
  80.  
  81.  
  82. }
  83.  
  84.  
  85.  
  86. -(UIImage *)drawText:(NSString *)text
  87. inImage:(UIImage *) image
  88. atPoint:(CGPoint) point{
  89.  
  90.  
  91. UIFont *font = [UIFont boldSystemFontOfSize:40];
  92.  
  93. UIGraphicsBeginImageContext(image.size);
  94.  
  95. [image drawAtPoint:point];
  96.  
  97. CGRect rect = CGRectMake(point.x, point.y, image.size.width, image.size.height);
  98.  
  99. [[UIColor redColor] set];
  100.  
  101. [text drawInRect:CGRectIntegral(rect) withFont:font];
  102.  
  103. image = UIGraphicsGetImageFromCurrentImageContext();
  104.  
  105. UIGraphicsEndImageContext();
  106.  
  107. return image;
  108. }
  109.  
  110.  
  111.  
  112. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement