Guest User

Untitled

a guest
Jul 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. //
  2. // Drop_AnimationViewController.m
  3. // Drop Animation
  4. //
  5. // Created by Prasanth on 1/11/10.
  6. // Copyright __MyCompanyName__ 2010. All rights reserved.
  7. //
  8.  
  9. #import "Drop_AnimationViewController.h"
  10.  
  11. @implementation Drop_AnimationViewController
  12.  
  13. - (void)checkCollison {
  14.  
  15. CGRect beginFrame1 = hole.frame;
  16. beginFrame1.origin = CGPointMake(0, 332);
  17. hole.frame = beginFrame1;
  18.  
  19. if (CGRectContainsRect(hole.frame, fallingImage.frame)) {
  20.  
  21. hole.hidden = YES;
  22. }
  23. }
  24.  
  25.  
  26.  
  27. /*
  28. // The designated initializer. Override to perform setup that is required before the view is loaded.
  29. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  30. if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  31. // Custom initialization
  32. }
  33. return self;
  34. }
  35. */
  36.  
  37. /*
  38. // Implement loadView to create a view hierarchy programmatically, without using a nib.
  39. - (void)loadView {
  40. }
  41. */
  42.  
  43. - (void)makeImageFall {
  44. CGRect beginFrame = fallingImage.frame;
  45. beginFrame.origin = CGPointMake(160,-40);
  46. [UIView beginAnimations:nil context:nil];
  47. [UIView setAnimationDuration:0.01];
  48. fallingImage.frame = beginFrame;
  49. [UIView commitAnimations];
  50.  
  51. CGRect beginFrame1 = hole.frame;
  52. beginFrame1.origin = CGPointMake(0, 332);
  53. hole.frame = beginFrame1;
  54.  
  55.  
  56. xPoint = arc4random() % 320 + 1;
  57. NSLog(@"xPoint:%i", xPoint);
  58. CGRect frame = fallingImage.frame;
  59. frame.origin = CGPointMake(xPoint,480);
  60. [UIView beginAnimations:nil context:nil];
  61. [UIView setAnimationDuration:3];
  62. fallingImage.frame = frame;
  63. [UIView commitAnimations];
  64.  
  65. if (CGRectContainsRect(hole.frame, fallingImage.frame)) {
  66.  
  67. hole.hidden = YES;
  68. }
  69.  
  70. [self checkCollison];
  71.  
  72. }
  73.  
  74. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  75. - (void)viewDidLoad {
  76. [super viewDidLoad];
  77. [self makeImageFall];
  78. [self checkCollison];
  79. [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(makeImageFall) userInfo:nil repeats:YES];
  80. }
  81.  
  82.  
  83.  
  84. /*
  85. // Override to allow orientations other than the default portrait orientation.
  86. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  87. // Return YES for supported orientations
  88. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  89. }
  90. */
  91.  
  92. - (void)didReceiveMemoryWarning {
  93. [NSTimer release];
  94. [hole release];
  95. [fallingImage release];
  96. // Releases the view if it doesn't have a superview.
  97. [super didReceiveMemoryWarning];
  98.  
  99. // Release any cached data, images, etc that aren't in use.
  100. }
  101.  
  102. - (void)viewDidUnload {
  103. [NSTimer release];
  104. [hole release];
  105. [fallingImage release];
  106. // Release any retained subviews of the main view.
  107. // e.g. self.myOutlet = nil;
  108. }
  109.  
  110.  
  111. - (void)dealloc {
  112. [NSTimer release];
  113. [hole release];
  114. [fallingImage release];
  115. [super dealloc];
  116. }
  117.  
  118. @end
Add Comment
Please, Sign In to add comment