gpt4 book ai didi

iphone - CGRectIntersectsRect Logic - 有没有更好/更简单的方法来完成我在这里尝试做的事情?

转载 作者:行者123 更新时间:2023-11-29 04:56:35 24 4
gpt4 key购买 nike

这就是我正在尝试做的事情..

我有字母表中所有字母的 UIImageViews。如果用户从字母表中向下平移一个字母来拼写一个单词,并且该字母被平移并放下,没有与任何其他字母相交,那么我假设他们没有拼写一个单词,所以我将此字母添加到临时字母中数组。

假设他们用 5 个字母做到了这一点。现在他们决定使用他们已经找出的 5 个字母来构建单词。

如何创建一个 if 条件来检查平移的字母片段是否与临时数组中存在的任何字母相交。

对于我想做的事情,似乎不能只是将我的 if 语句放在枚举 for 循环中。所以我不确定我能做什么。

这是我的伪代码+逻辑:http://pastie.org/2738238

if ([gestureRecognizer state] == UIGestureRecognizerStateEnded)
{

//If a letter has never been panned or the currentPanned letter does not intersect with a letter that was added to the tempLetterArray
//*letterintempLetterArray* = How do I test against all the letters in the array in the if condition?
if ([tempLetterArray count] < 1 || !CGRectIntersectsRect(currentLetter.frame, *letterIntempLetterArray*.frame))
{
//Letters that may become words if other letter images are panned next to it.
//Make the frame of letter larger so the frame intersects without having to overlap letter.
currentLetter.contentMode = UIViewContentModeCenter;
currentLetter.frame = CGRectInset(currentLetter.frame, -10, -10);

currentLetter.backgroundColor = [UIColor redColor];
[tempLetterArray addObject:currentLetter];

}

//If a word hasn't been built yet, and user pans letter next to existing letter on the screen, build the first word.
else if ([firstWordArray count] < 1 && CGRectIntersectsRect(currentLetter.frame, *letterIntempLetterArray*.frame))
{

//Align centers of the currentLetter and the *letterInTempWordArray* in which the currentLetter intersected with


//Remove the letter from the temp array, and add it to the firstWordArray
NSUInteger indexOfTempLetter = [tempLetterArray indexOfObject:*letterIntempLetterArray*];
UIImageView *tempLetter = [[tempLetterArray objectAtIndex: indexOfTempLetter] retain];
[tempLetterArray removeObjectAtIndex: indexOfTempLetter];
[firstWordArray insertObject: tempLetter atIndex:0];
[tempLetter release];

//Make the frame of letter larger so the frame intersects without having to overlap letter.
//Add the letter that was just dropped after
currentLetter.contentMode = UIViewContentModeCenter;
currentLetter.frame = CGRectInset(currentLetter.frame, -10, -10);

currentLetter.backgroundColor = [UIColor redColor];
[firstWordArray addObject: currentLetter];

}

//Start building the first word
else if ([firstWordArray count] > 1 && CGRectIntersectsRect(currentLetter.frame, *letterInFirstWordArray*.frame))
{
//Align centers of the currentLetter and the *letterInFirstWordArray* in which the currentLetter intersected with
//Do more stuff

}

//If the current letter intersects with a letter in temp letter array, and the first word array has already been built on
//Start building the second word (Basically do this until 5 words have been created)
else if ([firstWordArray count] > 1 && CGRectIntersectsRect(currentLetter.frame, *letterInTempLetterArray*.frame))
{
//Align centers of the currentLetter and the *letterInTempLetterArray* in which the currentLetter intersected with
//Do more stuff
}

}

最佳答案

BOOL touched = NO;

for(UIImageView* img in TemporedArrayOfLetter)
{
touched = CGRectIntersectsRect(currentLetter.frame,img.frame);
if(touched)break;
}
if(tapcount<1 && touched)
{
foo code;
}

希望对你有帮助。

关于iphone - CGRectIntersectsRect Logic - 有没有更好/更简单的方法来完成我在这里尝试做的事情?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7856694/

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