-2

我正在尝试触摸和移动 nsarray 内的对象。我不知道下一步该做什么。这是显示我正在尝试做的代码的代码(显然不起作用,但给出了一个想法)。也许有人可以指导我。

     cardKeys = [[NSArray alloc] initWithObjects:
            @"a",
            @"b",
            @"c",
            @"d",
                                 nil];

  -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
   {

{
    UITouch *myTouch = [touches anyObject];
  startPoint = [myTouch locationInView:self.view];

    [cardKeys:startPoint.x:startPoint.y];


}   


}
4

1 回答 1

0

Your code is poorly formatted. Ex. extraneous pair of curly braces in the method, incorrect indentation. You should consider reading a good book on Objective-C and iOS development, like Programming iOS 5.

Onto your question. I have no idea how you display the NSStrings in that array, why it's global and not a property/ivar, etc. but one way to make something draggable is to make it a UIView subclass, implement touchesBegan and touchesMoved (as you have), grab the point the user touched in your coordinate system, compare it to the point the person's finger is when it moves, then offset your position based on that.

于 2012-09-09T01:27:31.440 回答