0

我正在 iPhone 上开发一个关于游戏的大学项目,该项目基于在标签的网格视图中查找单词。我必须找出在拖动手指时检测到的标签(实际上它们是字母)。谁能帮我知道我可以使用哪些控件来查找在拖动时检测到的适当标签..

提前致谢..

4

2 回答 2

1

您可以使用它来获取您的标签。

注意你必须userinteractionEnabled = YES为你所有的UILabel

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];

    if ([touch.view isKindOfClass:[UILabel class]])
    {
        UILabel *label=(UILabel*)touch.view;
        NSLog(@"%@",label.text);
    }
}
于 2013-07-19T11:15:25.650 回答
0
//To know exact Label from grid of Label use Tag property of tag


//To drag selected Label
//use this code

    UITouch *touch = [[event touchesForView:Label] anyObject];

        // get delta
        CGPoint previousLocation = [touch previousLocationInView:Label];
        CGPoint location = [touch locationInView:Label];
        CGFloat delta_x = location.x - previousLocation.x;
        CGFloat delta_y = location.y - previousLocation.y;

        // move button
        Label.center = CGPointMake(Label.center.x + delta_x,
            Label.center.y + delta_y);
//Alphabet on label
NSString *alphabet = Label.text;
于 2013-07-19T11:20:43.800 回答