SORU
17 EYLÜL 2013, Salı


UİCollectionViewCell uzun basın jest

Bir uzun basın jest tanıyıcı (alt sınıf) UİCollectionView eklemek için nasıl merak ediyorum. Varsayılan olarak eklenir o belgeleri okudum, ama nasıl olduğunu çözemedim.

Yapmak istediğim şey: Bir hücre üzerinde uzun basın ( I have a calendar thingy from github ), aday olan ve daha sonra onunla bir şeyler yapmak. Cep longpressed ne olduğunu bilmek istiyorum. Bu geniş bir soru için üzgünüm, ama ya google veya benzeri daha iyi bir şey bulamadım

CEVAP
17 EYLÜL 2013, Salı


yapman gereken şey şu:

senin myCollectionViewController.h dosyası UIGestureRecognizerDelegate protokol ekleyin

@interface myCollectionViewController : UICollectionViewController<UIGestureRecognizerDelegate>

senin myCollectionViewController.m dosya:

- (void)viewDidLoad
{
    // attach long press gesture to collectionView
    UILongPressGestureRecognizer *lpgr 
       = [[UILongPressGestureRecognizer alloc]
                     initWithTarget:self action:@selector(handleLongPress:)];
    lpgr.minimumPressDuration = .5; //seconds
    lpgr.delegate = self;
    lpgr.delaysTouchesBegan = YES;
    [self.collectionView addGestureRecognizer:lpgr];
}

-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer.state != UIGestureRecognizerStateEnded) {
        return;
    }
    CGPoint p = [gestureRecognizer locationInView:self.collectionView];

    NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:p];
    if (indexPath == nil){
        NSLog(@"couldn't find index path");            
    } else {
        // get the cell at indexPath (the one you long pressed)
        UICollectionViewCell* cell =
        [self.collectionView cellForItemAtIndexPath:indexPath];
        // do stuff with the cell
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Leigh Momii

    Leigh Momii

    10 Mayıs 2006
  • UCBerkeley

    UCBerkeley

    3 Mayıs 2006
  • USI Events

    USI Events

    6 AĞUSTOS 2013