Question

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);
}
Was it helpful?

Solution

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);
                                      }
                                    }];
                 }];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top