UILongPressGestureRecognizer

Я пытаюсь создать приложение, в котором UIButtons можно перетаскивать, когда срабатывает жест UILongPressGestureRecognizer.

У меня:

UIGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];

И

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {
    CGPoint location = [recognizer locationInView:self.view];

    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            //NSLog(@"handleLongPress: StateBegan");
            break;
        case UIGestureRecognizerStateChanged:
            if(location.y > 75.0 && location.x > 25 && location.x < 300)
                button.frame = CGRectMake(location.x-25, location.y-15, 50, 30);           
            break;
        case UIGestureRecognizerStateEnded:
            //NSLog(@"handleLongPress: StateEnded");
            break;
        default:
            break;
    }   
}

Это отлично работает с одной кнопкой (а именно с кнопкой ivar ). Как я могу отправить в функцию handleLongPress текущую нажатую кнопку? Другими словами, Я хотел бы сделать что-то вроде следующего, где я передаю отправитель

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer:(id)sender {
    CGPoint location = [recognizer locationInView:self.view];

    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            //NSLog(@"handleLongPress: StateBegan");
            break;
        case UIGestureRecognizerStateChanged:
            if(location.y > 75.0 && location.x > 25 && location.x < 300)
                sender.frame = CGRectMake(location.x-25, location.y-15, 50, 30);           
            break;
        case UIGestureRecognizerStateEnded:
            //NSLog(@"handleLongPress: StateEnded");
            break;
        default:
            break;
    }   
}
10
задан EmptyStack 30 August 2011 в 10:17
поделиться