这就是我想要做的。
我有所有字母的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;
}
希望对您有帮助。