UILongPressGestureRecognizer

Ich versuche eine app erstellen, wo UIButtons werden kann, gezogen und abgelegt, wenn UILongPressGestureRecognizer Geste ausgelöst wird.

Habe ich:

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

Und

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

Dies funktioniert mit einer Taste (nämlich die ivar button). Wie kann ich senden, um die handleLongPress Funktion die aktuelle Taste, die gedrückt wird? In anderen Worten, ich möchte etwas tun, wie die folgenden, wo ich den pass in 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;
    }   
}
InformationsquelleAutor v0idless | 2011-05-18
Schreibe einen Kommentar