这就是我要做的......
我有字母表中所有字母的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
}
}
答案 0 :(得分:1)
BOOL touched = NO;
for(UIImageView* img in TemporedArrayOfLetter)
{
touched = CGRectIntersectsRect(currentLetter.frame,img.frame);
if(touched)break;
}
if(tapcount<1 && touched)
{
foo code;
}
希望对你有所帮助。