-->

detect collision of two moving buttons in iPhone

2020-07-18 11:16发布

问题:

I am using the below function to move two buttons on the screen

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished));

Now I want to detect the collision of those moving button.

So I want to know is there any event which is getting fired when the object is animating(moving). Or where else can I place my condition of

CGRectIntersectsRect(,);

回答1:

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished));

is a "fire and forget" type animation. You don't have access to the internals. It's automatic.

If you need to do collision detection, you can use a 2D sprite library like Cocos2D or you can set up a timer to move and animate the buttons manually.