【问题标题】:Pinch Zoom in and Zoom Out in Objective c在目标 c 中捏合放大和缩小
【发布时间】:2012-07-11 06:14:19
【问题描述】:

如何在我们的应用程序中集成捏缩放和缩小,我在 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;
    }

}

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

谢谢;

【问题讨论】:

    标签: iphone objective-c cocoa pinchzoom


    【解决方案1】:

    如果您已经在使用UIScrollView,则无需使用UIGestureRecognizersUIScrollView 支持双指缩放。

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

    【讨论】:

    • 感谢您的快速转身。我正在使用滚动视图,但是当我在缩放中返回任何对象时,我有三个图像对象当前、上一个和下一个,代表其缩放的多个图像。
    • 您是否尝试在照片应用中实现图像浏览器?在哪里滑动查看下一张图片?
    • 完全正确..我正在尝试与照片应用程序相同..任何想法。
    • 不要重新发明轮子。这个特性在网络上有几个实现。只是搜索。示例:MWPhotoBrowser
    • WWDC 2010 中有一个类描述了如何实现 iPhoto 风格的照片浏览器。从 2012 年开始,有一个类显示无限滚动。 2011年也不错。您可以通过 develop.apple.com 访问视频(需要会员资格)。
    【解决方案2】:
    -(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;}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 2012-04-18
      • 2014-10-23
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      • 1970-01-01
      相关资源
      最近更新 更多