Подтвердить что ты не робот

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 button). Как я могу отправить функции handleLongPress текущую нажатую кнопку? Другими словами, я хотел бы сделать что-то вроде следующего, где я перехожу в sender

- (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;
    }   
}
4b9b3361

Ответ 1

Вы попробовали recognizer.view?

Ответ 2

Вам нужно будет пропустить всю вашу кнопку в handleLongPress. Использование locationInView и pointInside: withEvent: определить, какая кнопка находится под нажатием пальца.