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);
}
有帮助吗?

解决方案

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);
                                      }
                                    }];
                 }];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top