1

如何在我们的应用程序中集成捏缩放和缩小,我在 scrollView 上使用 imageview,我的代码是:

- (IBAction)handlePinchGesture:(UIGestureRecognizer *) recognizer {
    if(zoomEnable == TRUE)
    {

        CGFloat factor = [(UIPinchGestureRecognizer *) recognizer scale];
        CGFloat lastScaleFactor = 1;

        //if the current factor is greater 1 --> zoom in
        if (factor > 1) {
            scrollView.transform = CGAffineTransformMakeScale(lastScaleFactor + (factor-1),lastScaleFactor + (factor-1));
            scrollView.scrollEnabled = YES;

        } else {

            [UIView beginAnimations:@"animation" context:nil];
            [UIView setAnimationDuration:0.5];
            [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:scrollView cache:NO];
            scrollView.transform = CGAffineTransformMakeScale(1,1);     
            [UIView commitAnimations];

        }
        isScrollable = TRUE;
    }

}

它每次从我想要的开始缩放时开始缩放,然后在我停止缩放时再次开始。非常感谢任何帮助

谢谢;

4

2 回答 2

1

UIGestureRecognizers如果您已经在使用,则无需使用UIScrollViewUIScrollView支持捏缩放。

要使缩放和平移工作,代理必须同时实现viewForZoomingInScrollView:and scrollViewDidEndZooming:withView:atScale:; 此外,最大 ( maximumZoomScale) 和最小 ( minimumZoomScale) 缩放比例必须不同。

于 2012-07-11T06:15:59.070 回答
0
-(void)zoomingImages{ 
    self.FullSizeScrollView.pagingEnabled =YES;
    NSMutableArray *_scrollArray =[[NSMutableArray alloc]init];

    // add images to scroll array

        [_scrollArray addObject:self.image1];
        [_scrollArray addObject:self.image2];

    //now call init with frame function given below to set frame for each image in scroll view
    for(int i =0 ;i<[_scrollArray count];i++){
        ZoomingImageView *_imageScrollView = [[ZoomingImageView alloc]initWithFrame:CGRectMake(i*320, 0, 320, 460)];
        _imageScrollView.captureView=self;      
        [self.checkFullSizeScrollView addSubview:_imageScrollView];
        [_imageScrollView release];
        self.checkFullSizeScrollView.contentSize = CGSizeMake((i*320)+320, 460);
    }

    [_scrollArray release];
}


@implementation ZoomingImageView

- (id)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];

      if (self) {

        self.maximumZoomScale = 4;
        self.minimumZoomScale = 1;     
        self.userInteractionEnabled = YES;
        self.multipleTouchEnabled = YES;
        self.delegate = self;
        self.bouncesZoom = NO;
        self.currentImageView.clipsToBounds=NO;
        self.contentMode =UIViewContentModeScaleAspectFit;
        UIImageView *zoomImageView_ =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        self.currentImageView = zoomImageView_;
        [zoomImageView_ release];
         self.currentImageView.contentMode =UIViewContentModeScaleAspectFit;
        self.currentImageView.userInteractionEnabled = YES;
        self.currentImageView.multipleTouchEnabled = YES;
        [self addSubview:self.currentImageView];}
return self;}
于 2012-07-11T07:36:34.413 回答