首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在collison检测中调用CGRectIntersectsRect时出现问题

在collison检测中调用CGRectIntersectsRect时出现问题
EN

Stack Overflow用户
提问于 2011-04-13 20:03:08
回答 1查看 832关注 0票数 0

我想在两个imageViews相交时进行碰撞检测。下面是我用于碰撞检测的代码。

代码语言:javascript
复制
- (void)onTimer
{
// build a view from our flake image
flakeView = [[UIImageView alloc] initWithImage:flakeImage];
flakeView.backgroundColor=[UIColor blueColor];

// use the random() function to randomize up our flake attributes
int startX =round(random() % 460);  
printf("\n ===== startX :%d",startX);
int endX = round(random() % 460);
printf("\n ===== endX :%d",endX);

double scale = 1 / round(random() % 100) - 1.0;
double speed = 1 / round(random() %100) + 1.0;

// set the flake start position
flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
flakeView.alpha = 1.0;

// put the flake in our main view
[mView addSubview:flakeView];

[UIView beginAnimations:nil context:flakeView];
[UIView setAnimationDuration:20 * speed];


if(dragger.setFrame==YES)

{

    printf("\n =====dragger.frame.origin.x:%f",dragger.frame.origin.x);

    printf("\n =====dragger.frame.origin.y:%f",dragger.frame.origin.y);

    flakeView.frame = CGRectMake(dragger.frame.origin.x, dragger.frame.origin.y, 25.0 *  scale, 25.0 * scale);

    printf("\n =====flakeView.frame.origin.x:%f",flakeView.frame.origin.x);
    printf("\n =====flakeView.frame.origin.y:%f",flakeView.frame.origin.y);



    if(CGRectIntersectsRect(flakeView.frame,dragger.frame))
    {
        NSLog(@"\nRect is Intersecting");

    }
    dragger.setFrame=NO;
}

else 
{
    flakeView.frame = CGRectMake(endX, 500.0, 25.0 * scale, 25.0 * scale);


}


[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];

 }

在这个drager框架中是一个inageView的框架。当我们将此图像拖动到flakeview图像上时,该方法

代码语言:javascript
复制
if(CGRectIntersectsRect(flakeView.frame,dragger.frame))

不会被召唤。在这方面,有人能帮上忙吗?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2011-04-13 20:33:02

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5648869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档