-2

I have an object that falls from the top of the screen however i want it to come back up after the bottom of the object reaches the bottom of the screen. This is my code at the moment. I tried adding another image view to trigger the up motion by collision. The timer is in ViewDidLoad

hammer.center = CGPointMake(hammer.center.x, hammer.center.y + 12);

if (CGRectIntersectsRect(hammer.frame, floor.frame)) {
        hammer.center = CGPointMake(hammer.center.x , hammer.center.y -50);
}
Connor Pearson
  • 63,902
  • 28
  • 145
  • 142

1 Answers1

1

you wont see it animate, maybe try animating the view instead of moving it instantly.

Place this in viewDidAppear to see it after the view has come on the screen.

[UIView animateWithDuration:0.3f
                 animations:^{
                   hammer.center = CGPointMake(hammer.center.x, hammer.center.y + 12);
                 } completion:^(BOOL finished) {
                   [UIView animateWithDuration:0.3f
                                    animations:^{
                                      if (CGRectIntersectsRect(hammer.frame, floor.frame)) {
                                        hammer.center = CGPointMake(hammer.center.x , hammer.center.y -50);
                                      }
                                    }];
                 }];
Oliver Atkinson
  • 7,970
  • 32
  • 43