ho diversi UIImageView, ognuno di essi ha un tag; e ho una serie di immagini, quello che voglio fare è: quando l'utente tocca uno dei UIImageView, l'app restituisce la determinata immagine da matrice.come ottenere il tag di UIImageView che sto toccando?
a implementare in questo modo:
- (void)viewDidLoad
{
[super viewDidLoad];
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:scroll];
NSInteger i;
for (i=0; i<8; i++)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, i*100 + i*15, 300, 100)];
imageView.backgroundColor = [UIColor blueColor];
imageView.userInteractionEnabled = YES;
imageView.tag = i;
NSLog(@"%d", imageView.tag);
[scroll addSubview:imageView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(findOutTheTag:)];
[imageView addGestureRecognizer:tap];
}
scroll.contentSize = CGSizeMake(320, 115*i);
}
- (void)findOutTheTag:(id)sender
{
// HOW TO FIND THE tag OF THE imageView I'M TAPPING?
}
Voglio scoprire la imageView.tag
, e passare a imageView.tag
UIImageView *tappedImage = [imageArray objectAtIndex:imageView.tag];
per visualizzare l'immagine.
Ho taggato tutti, la domanda è come posso scoprire lo tag
di imageView Sto toccando? grazie per aver letto^_^
Il mittente qui è il riconoscitore di gesti, quindi è necessario eseguire 'switch (((UIGestureRecognizer *) mittente .view.tag)'. – Anna
@aBitObvious buona raccolta! – Rog
+1 - (vuoto) childTapped: (UITapGestureRecognizer *) tapGesture {int tag = tapGesture.view.tag;} // ha funzionato per me – HDdeveloper