【发布时间】:2023-04-09 09:19:01
【问题描述】:
这就是我想要做的..
我有所有字母的 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
}
}
【问题讨论】:
标签: iphone objective-c ios ipad uiimageview