【发布时间】:2013-11-03 11:33:20
【问题描述】:
我正在开发一款经典游戏“找词” 像这个寻找“狮子”的例子
G H K J L D F G F Y E
J L M N L I O N A D T
G F O I A F E A D G H ...
我有这个代码来获取所有的字母值
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[self touchesBegan:touches withEvent:event];
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [[touches anyObject] locationInView:allLetters];
for (UILabel *letter in self.lettersArray) {
if (touchPoint.x > letter.frame.origin.x &&
touchPoint.x < letter.frame.origin.x + letter.frame.size.width &&
touchPoint.y > letter.frame.origin.y &&
touchPoint.y < letter.frame.origin.y + letter.frame.size.height )
{
[letter setBackgroundColor:[UIColor redColor]];
NSLog(@"%@",letter.text);
}
}}
它运行良好,因为当我用手指触摸标签文本时,它会正确获取它们。我的问题是我只需要获得一次价值......
现在它会多次获取该值,直到您传递给另一个字母
你有什么建议吗?
非常感谢!!
【问题讨论】:
标签: ios uilabel touch-event