gpt4 book ai didi

ios - CGRectIntersectsRect 框架 + -10

转载 作者:行者123 更新时间:2023-11-29 03:02:46 24 4
gpt4 key购买 nike

我有一个问题。

我希望两个物体发生碰撞。这是我当前的代码:

if (CGRectIntersectsRect(_redBall.frame, _boxRed.frame)) {


score = score + 10;
_redBall.center = CGPointMake(240, 160);

_scoreLabel.text = [NSString stringWithFormat:@"Score: %i", score];


}

我希望这两个对象(_redBall 和 _boxRed)发生碰撞,但它们在(例如)帧 -10 或其他值发生碰撞。这可能吗?

最佳答案

尝试使用 UIEdgeInsetsInsetRect

CGRect original = CGRectMake(0, 0, 100, 100);
UIEdgeInsets adjustment = UIEdgeInsetsMake(-5, 10, 20, -30); // top, left, bottom, right
CGRect adjustedRect = UIEdgeInsetsInsetRect(original, adjustment);

// adjustedRect = {10, -5, 130, 80}

这将允许您调整所有边缘,从而调整 CGRect 的位置。

正如有人提到的,还有 CGRectOffset ,但这只会移动矩形。如果你想扩展它,你可以使用UIEdgeInsets

还有 CGRectInset这类似于 UIEdgeInsets,但只会一起增长或扩展同一轴上的边缘,而不是单独增长或扩展边缘。

我只提到了所有三种方法,因为您对 frame - 10 有点模糊。不过,以上所有内容都应该对您有所帮助!

关于ios - CGRectIntersectsRect 框架 + -10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23130091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com