iPhone手势监控 代码

 

 // add gesture recognizers to the image view

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer allocinitWithTarget:self action:@selector(handleSingleTap:)];

    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer allocinitWithTarget:self action:@selector(handleDoubleTap:)];

    UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer allocinitWithTarget: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];

 

#pragma mark TapDetectingImageViewDelegate methods

 

- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {

    // single tap does nothing for now

}

 

- (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];

}

posted on 2012-11-15 18:07  无量少年  阅读(287)  评论(0编辑  收藏  举报

导航