Domanda

Ho una vista da tavolo che vorrei scorrere quando una cella selezionata e "pop" è uscita e spostalo intorno alla vista tabella. La vista tabella scorre salta solo e la pressione lunga per selezionare una cella funziona, ma non sono in grado di scorrere la vista tabella quando ho una cella selezionata.

Ho letto su UIGestureRecognizerDelegate ma non sono sicuro che stia facendo la differenza. Io chiamò anche questi metodi

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}
.

Ecco parte del mio codice:

- (IBAction)longPressGestureRecognized:(id)sender {

UILongPressGestureRecognizer *longPress = (UILongPressGestureRecognizer *)sender;
UIGestureRecognizerState state = longPress.state;
//longPress.delegate = self;

CGPoint location = [longPress locationInView:self.personTableView];
NSIndexPath *indexPath = [self.personTableView indexPathForRowAtPoint:location];

static UIView       *snapshot = nil;        ///< A snapshot of the row user is moving.
static NSIndexPath  *sourceIndexPath = nil; ///< Initial index path, where gesture begins.

switch (state) {
    case UIGestureRecognizerStateBegan: {
        if (indexPath) {
            sourceIndexPath = indexPath;

            UITableViewCell *cell = [self.personTableView cellForRowAtIndexPath:indexPath];
            // capture the color of the cell before blacking out
            savedTextColor = cell.detailTextLabel.textColor;

            // Take a snapshot of the selected row using helper method.
            snapshot = [self customSnapshotFromView:cell];

            // Add the snapshot as subview, centered at cell's center...
            __block CGPoint center = cell.center;
            snapshot.center = center;
            snapshot.alpha = 0.0;
            [self.personTableView addSubview:snapshot];
            [UIView animateWithDuration:0.25 animations:^{

                // Offset for gesture location.
                center.y = location.y;
                snapshot.center = center;
                snapshot.transform = CGAffineTransformMakeScale(1.05, 1.05);
                snapshot.alpha = 0.98;

                // Black out.
                cell.detailTextLabel.alpha = 0;
                cell.textLabel.alpha = 0;
            } completion:nil];
        }
        break;
    }
    case UIGestureRecognizerStateChanged: {
        CGPoint center = snapshot.center;
        center.y = location.y;
        snapshot.center = center;

        // Is destination valid and is it different from source?
        if (indexPath && ![indexPath isEqual:sourceIndexPath]) {

            // ... update data source.
            [dataSingelton saveUpdatedPersonList:(int)indexPath.row sourceIndex:(int)sourceIndexPath.row];
            //[[dataSingelton mutableDataArray] exchangeObjectAtIndex:indexPath.row withObjectAtIndex:sourceIndexPath.row];

            // ... move the rows.
            [self.personTableView moveRowAtIndexPath:sourceIndexPath toIndexPath:indexPath];

            // ... and update source so it is in sync with UI changes.
            sourceIndexPath = indexPath;
        }
        break;
    }

    default: {
        // Clean up.
        UITableViewCell *cell = [self.personTableView cellForRowAtIndexPath:sourceIndexPath];
        [UIView animateWithDuration:0.25 animations:^{
            snapshot.center = cell.center;
            snapshot.transform = CGAffineTransformIdentity;
            snapshot.alpha = 0.1;
            cell.detailTextLabel.alpha = 1;
            cell.textLabel.alpha = 1;
        } completion:^(BOOL finished) {
            [snapshot removeFromSuperview];
            snapshot = nil;
            cell.hidden = NO;
        }];
        sourceIndexPath = nil;
        break;
    }
}
.

}

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}



- (UIView *)customSnapshotFromView:(UIView *)inputView {

    UIView *snapshot = [inputView snapshotViewAfterScreenUpdates:YES];
    snapshot.alpha = 0.1;
    snapshot.layer.masksToBounds = NO;
    snapshot.layer.cornerRadius = 0.0;
    snapshot.layer.shadowOffset = CGSizeMake(-5.0, 0.0);
    snapshot.layer.shadowRadius = 5.0;
    snapshot.layer.shadowOpacity = 0.4;
    return snapshot;
}
.

Quando ho impostato il delegato in se stesso come questo:

longPress.delegate = self;
.

La vista Abile Scorri, ma quindi la mia cella selezionata non si muove. Cosa mi manca per fare questo lavoro?

* Aggiornato * Dopo aver fatto un po 'di più lettura / ricerca, penso che per me per raggiungere l'effetto che voglio (l'effetto di scorrimento sul tableview nell'app meteo di Apple) penso che il mio lungo gesto della stampa dovrà anche gestire lo scorrimento della mia vista da tavolo. Lo scorrimento predefinito inizia a scorrere istantaneamente l'intera tabella, dove come ho bisogno della tabella per scorrere solo quando la cella pressata lunga è in alto o in fondo alla mia tabella. Sono corretto nel pensare in questo modo? Ho cercato di trovare un esempio per abbattere e studiare, ma non ho avuto fortuna a trovare qualcosa del genere.

** Aggiornato ** Quindi sto cercando di capire come scatenare il timer di scorrimento quando l'utente trascina una cella verso l'alto verso l'alto. Il problema che sto facendo ora è capitando quando quella cella è vicina all'inizio, quando è in cima alla parte superiore del tableview, è facile usare qualcosa come tableViewHight + 100, ma questo codice non funziona quando il tableView è scaduto . Ecco cosa ho finora:

NSLog(@"This is table view hight %.2f", tableViewHight);

            NSLog(@"This is content offset %f",  (personTableView.contentOffset.y));

            NSLog(@"Should be 100 place holder %.2f", (tableViewHight - tableViewHight) + personTableView.contentOffset.y + 100);

            NSLog(@"location y %f", location.y);



            // gets called repeatedly
            // Step 1: check to see if we need to start scrolling
            if (location.y < tableViewHight - tableViewHight + 100) {
                // ** top **
                // Step 2: make sure the current y postoin isn't greater then the previous y postion
                if (location. y <= originalLocation.y) {
                   // NSLog(@"This is the offset y %f", self.personTableView.contentOffset.y);

                        // Step 4: check to see if we have a timer and if not create one
                        [self startTimer];


                }
                else{
                    //Step 3: they started to scroll up so end the timer
                    [self endTimer];
                }
            }
            else if(location.y > tableViewHight - 100)
            {
                // ** bottom **
                // Step 2: make sure the current y postoin isn't less then the previous y postion
                if (location. y >= originalLocation.y) {

                        NSLog(@"its less then 0");
                        if (!timer) {
                            // Step 4: check to see if we have a timer and if not create one
                            [self startTimer];
                        }


                }
                else{
                     //Step 3: they started to scroll up so end the timer
                    [self endTimer];
                }
            }
            else{
                // ** middle **
                // Step 2: check to see if we have a timer and if so destory it
                [self endTimer];
            }
.

Fondamentalmente voglio scatenare che se la dichiarazione quando la cella è meno di 100 px dal lungomare della vista tabella scorrevole.

È stato utile?

Soluzione

Dal UILongPressGestureRecognizer è possibile ottenere la posizione corrente y del tatto.Da ciò è possibile calcolare quanto vicino al fondo o in alto del touch UITableViewthe.Se si determina che è abbastanza vicino per iniziare a scorrere, quindi avviare un NSTimer ripetuto che incrementa o decrementa il contentoffset del tuo UITableView da 1 pixel, scorrendo la tabella.Cambia quanto veloce scorre scorrendo la generazione timeInterval del timer.

Quando termina il UILongPressGestureRecognizer, o se la posizione y del touch si sposta al di fuori della zona di scorrimento, quindi invalida il timer, che interromperà lo scorrimento.

Se ti sentivi avventuroso potresti anche aumentare la velocità dello scorrimento in modo dinamico in quanto l'utente si avvicina al bordo del generatore UITableView modificando il timeInterval poiché l'utente sposta il loro tocco verso l'alto o verso il basso, poiché è generalmente come questo tipo diFunzionalità funziona.

Buona fortuna!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top