SORU
11 Ocak 2011, Salı


Nasıl bir UİView için dokunmatik bir olay eklemek için?

Nasıl bir UİView için dokunma olayı eklerim?
Ben deneyin:

UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, nextY)] autorelease];
[headerView addTarget:self action:@selector(myEvent:) forControlEvents:UIControlEventTouchDown];
// ERROR MESSAGE: UIView may not respond to '-addTarget:action:forControlEvents:'

Alt ve üzerine yaratmak istemiyorum

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

Teşekkürler!

CEVAP
11 Ocak 2011, Salı


İOS 3.2 ve üstü, jest tanıyıcıları kullanabilirsiniz. Örneğin, bu musluk olayı nasıl idare ederdiniz

//The setup code (in viewDidLoad in your view controller)
UITapGestureRecognizer *singleFingerTap = 
  [[UITapGestureRecognizer alloc] initWithTarget:self 
                                          action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleFingerTap];
[singleFingerTap release];

//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
  CGPoint location = [recognizer locationInView:[recognizer.view superview]];

  //Do stuff here...
}

Dahili hareketler bir sürü de vardır. İOS olay işleme ve UIGestureRecognizer için belgeleri kontrol. Ben de yardımcı olabilecek github örnek kodu bir grup var.

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Jonathan D.

    Jonathan D.

    3 Kasım 2006
  • Matt Davis

    Matt Davis

    4 ŞUBAT 2006
  • Chaîne de TheMoustic

    Chaîne de T

    5 Kasım 2006