UITapGestureRecognizer
Je vérifier d'Apple ScrollView suite un exemple de code. Lorsque je l'utilise dans mon code alors que cela ne fonctionne pas alors que je n'avais pas fait le changement.Je me demandais juste comment je ne peux pas obtenir un double-tap pour annuler le zoom à l'intérieur d'un rouleau de vue? Je ne peux pas semblent le comprendre. Je suis insérer une image à partir de l'URL alors que dans l'exemple de code faites glisser une image dans interface builder. J'ai aussi essayer avec le même code, mais de reconnaître appuyez sur l'image ne fonctionne pas. Pourquoi c'est arrivé, je ne peux pas l'obtenir? Je montre aussi mon code ci-dessous:
- (void)loadView {
[super loadView];
//set the tag for the image view
[imageView setTag:ZOOM_VIEW_TAG];
//add gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
[doubleTap setNumberOfTapsRequired:2];
[twoFingerTap setNumberOfTouchesRequired:2];
[imageView addGestureRecognizer:singleTap];
[imageView addGestureRecognizer:doubleTap];
[imageView addGestureRecognizer:twoFingerTap];
[singleTap release];
[doubleTap release];
[twoFingerTap release];
NSURL *imgUrl=[[NSURL alloc] initWithString:@"http://www.iso.org/iso/alan_bryden_larger.jpg"];
NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
UIImage *img = [UIImage imageWithData:imgData];
imageView = [[UIImageView alloc] initWithImage:img];
[self.imageScrollView addSubview:imageView];
[imgUrl release];
//calculate minimum scale to perfectly fit image width, and begin at that scale
float minimumScale = [imageScrollView frame].size.width / [imageView frame].size.width;
[imageScrollView setMinimumZoomScale:minimumScale];
[imageScrollView setZoomScale:minimumScale];}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [imageScrollView viewWithTag:ZOOM_VIEW_TAG];}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
[scrollView setZoomScale:scale+0.01 animated:NO];
[scrollView setZoomScale:scale animated:NO];}
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
//double tap zooms in
float newScale = [imageScrollView zoomScale] * ZOOM_STEP;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
[imageScrollView zoomToRect:zoomRect animated:YES];}
- (void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer {
//two-finger tap zooms out
float newScale = [imageScrollView zoomScale] / ZOOM_STEP;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
[imageScrollView zoomToRect:zoomRect animated:YES];}
source d'informationauteur Neha
Vous devez vous connecter pour publier un commentaire.
Votre
UIImageView
ne passera pas touche à unUIGestureRecognizer
sauf si vous avezuserInteractionEnabled = YES
.Vous ajoutez des gestes pour imageView, alors vous allouer un nouveau UIImageView et en ajoutant à la scrollView. C'est le problème, je suppose. Réorganiser votre code,
Assurez-vous de définir le
userInteractionEnabled
propriété: