Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UIImageView和CGRect(Xcode)_Objective C_Ios_Uiimageview - Fatal编程技术网

Objective c UIImageView和CGRect(Xcode)

Objective c UIImageView和CGRect(Xcode),objective-c,ios,uiimageview,Objective C,Ios,Uiimageview,我有两个uiimageview,它们的大小分别为50x50和60x60像素 我使用CGRectIntersectRect方法来确定一个图像何时与另一个图像接触。但这两个图像是两个球,有时代码会确定这些图像在“用你的眼睛”看到它们不接触时是在接触自己。这是因为球并没有“覆盖”图像的所有空间。因此,图像的各个角落都很清晰,但代码当然不关心这一点 问题是:我如何解决?如何确定完全沿着球体周长的图像帧?如果您确定UIImageViews中的图像始终是圆形(或者UIImageViews始终是方形),则可以

我有两个
uiimageview
,它们的大小分别为50x50和60x60像素

我使用
CGRectIntersectRect
方法来确定一个图像何时与另一个图像接触。但这两个图像是两个球,有时代码会确定这些图像在“用你的眼睛”看到它们不接触时是在接触自己。这是因为球并没有“覆盖”图像的所有空间。因此,图像的各个角落都很清晰,但代码当然不关心这一点


问题是:我如何解决?如何确定完全沿着球体周长的图像帧?

如果您确定
UIImageView
s中的图像始终是圆形(或者
UIImageView
s始终是方形),则可以执行以下操作:

CGRect frame1 = image1.frame;
CGRect frame2 = image2.frame;
CGPoint center1 = CGPointMake(CGRectGetMidX(frame1), CGRectGetMidY(frame1));
CGPoint center2 = CGPointMake(CGRectGetMidX(frame2), CGRectGetMidY(frame2));

CGFloat dx = center1.x - center2.x;
CGFloat dy = center2.x - center2.y;
float squaredDistance = dx * dx + dy * dy;

CGFloat radius1 = frame1.size.width/2;
CGFloat radius2 = frame2.size.width/2;
CGFloat minDistance = radius1 + radius2;
if (squaredDistance <= minDistance * minDistance) {
    //Intersect
} else {
    //Do not intersect
}
#define RADIUS1 25
#define RADIUS2 30
并简化您的代码

我假设每个圆都内接在
UIImageView
的框架中。如果没有,那么您应该知道正确测量半径的准确比率。(到目前为止,在框架中内接圆圈更容易。)