Iphone 检查移动时两个图像视图是否相交

Iphone 检查移动时两个图像视图是否相交,iphone,uiimageview,Iphone,Uiimageview,我正在开发一个应用程序,其中一个图像视图沿圆周方向移动,并检查它是否与任何其他视图相交 这是一个正在移动的图像视图 circleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo16.png"]]; circleView.frame = CGRectMake(30 , 30, 30, 30); 这是另一个视图,我想检查它是否相交 detectrect=[[UIImageView alloc]initWithI

我正在开发一个应用程序,其中一个图像视图沿圆周方向移动,并检查它是否与任何其他视图相交

这是一个正在移动的图像视图

circleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo16.png"]];
circleView.frame = CGRectMake(30 , 30, 30, 30);
这是另一个视图,我想检查它是否相交

detectrect=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"logo16.png"]];
detectrect.frame=CGRectMake(160, 160, 80, 80);



[self.view addSubview:detectrect];


[self.view addSubview:circleView];
现在我有了一个方法,我用定时器检查它们是否相交

[NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(imageviewcoordinates) userInfo:nil repeats:YES];

-(void)imageviewcoordinates;
{

}

我无法发现它
不知道这里出了什么问题

我要做的第一件事是从imageviewcoordinates方法向调试区域输出一些NSLog:

NSLog(@" self.detectrect.frame.origin.x : %f ", self.detectrect.frame.origin.x);
NSLog(@" self.detectrect.frame.origin.y : %f ", self.detectrect.frame.origin.y);

NSLog(@" self.detectrect.frame.size.width : %f ", self.detectrect.frame.size.width);
NSLog(@" self.detectrect.frame.size.height : %f ", self.detectrect.frame.size.height);

NSLog(@" self.circleView.frame.origin.x : %f ", self.circleView.frame.origin.x);
NSLog(@" self.circleView.frame.origin.y : %f ", self.circleView.frame.origin.y);

NSLog(@" self.circleView.frame.size.width : %f ", self.circleView.frame.size.width);
NSLog(@" self.circleView.frame.size.height : %f ", self.circleView.frame.size.height);

为了确保获得一些值,您可以进行比较,以便了解CGRectContainesRect失败的原因。

如果CGRectIntersectsRectPhoto.frame,photo2.frame
用这个来检查十字路口

嗨,艾德,是的,我检查过了,我正在做NSLog@x=%f,circleView.frame.origin.x;bt我每次移动时都得到相同的值?30岁了,我能看到图像视图在移动,这会有什么问题?为什么会出现这种奇怪的行为?请在添加子视图后尝试设置框架。您应该创建uiview,将其添加到视图层次结构子视图(在您的情况下),设置初始位置/帧,然后设置动画。嘿,ade我尝试了bt不工作,下面是图像视图循环移动动画的全部代码CAKeyframeAnimation*pathAnimation=[CAKeyframeAnimation animation WithKeyPath:@position];pathAnimation.calculationMode=kCAAnimationPaced;pathAnimation.fillMode=kCAFillModeForwards;pathAnimation.removedOnCompletion=否;pathAnimation.duration=3.0;pathAnimation.repeatCount=10;CGMutablePathRef curvedPath=CGPathCreateMutable;450;CGPathAddArccurvedPath,NULL,160260,160/2,0,45*M_PI*2,是;pathAnimation.path=曲线路径;CGPathReleasecurvedPath;您的视图没有移动。您正在为UIView的核心动画层设置动画,而不是视图本身。您需要为视图而不是层设置动画,或者检测层的交点。
NSLog(@" self.detectrect.frame.origin.x : %f ", self.detectrect.frame.origin.x);
NSLog(@" self.detectrect.frame.origin.y : %f ", self.detectrect.frame.origin.y);

NSLog(@" self.detectrect.frame.size.width : %f ", self.detectrect.frame.size.width);
NSLog(@" self.detectrect.frame.size.height : %f ", self.detectrect.frame.size.height);

NSLog(@" self.circleView.frame.origin.x : %f ", self.circleView.frame.origin.x);
NSLog(@" self.circleView.frame.origin.y : %f ", self.circleView.frame.origin.y);

NSLog(@" self.circleView.frame.size.width : %f ", self.circleView.frame.size.width);
NSLog(@" self.circleView.frame.size.height : %f ", self.circleView.frame.size.height);