【问题标题】:UIImageView in UIScrollView, zooming is jitteryUIScrollView中的UIImageView,缩放很抖动
【发布时间】:2013-06-25 07:18:29
【问题描述】:

我在 UIScrollview 中有一个 UIImageView。我使用了 Apple 的 docs 中的说明。

我设置了最小和最大缩放比例。 (0.5 和 6.0)。我将委托设置为自我。

我在 viewForZoomingInScrollView 中返回了图像视图。但是我不知道在 scrollViewDidEndZooming 中该怎么做。

我得到的结果是抖动的缩放并且不一致。它只是表现得不像照片库应用。

我错过了什么吗?

【问题讨论】:

    标签: uiscrollview uiimageview zooming pinchzoom


    【解决方案1】:
    //create imageview with pinchGesture
    
            CGRect myImageRect = CGRectMake(17, 95, 285, 130);
            myImage = [[UIImageView alloc] initWithFrame:myImageRect];
            [myImage setImage:[UIImage imageNamed:picture]];
            myImage.userInteractionEnabled = YES;
            UIPinchGestureRecognizer *pgr = [[UIPinchGestureRecognizer alloc]
                                             initWithTarget:self action:@selector(handlePinch:)];
            pgr.delegate = self;
            [myImage addGestureRecognizer:pgr];
            [scrollview addSubview:myImage];
    

    //句柄:方法

    - (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
    {
     recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform,   recognizer.scale, recognizer.scale);
    recognizer.scale = 1;
    }
    

    在此之前添加 .h 文件

    希望对你有用...

    【讨论】:

    • 缩放工作顺利,但图像有时会超出右侧,我认为这是因为 scrollView 的平移。平移有时会干扰缩放,并且随着我放大更多,平移会减小。我应该完全消除滚动视图并在图像视图上实现平移手势吗?无论如何,有没有办法让它的行为就像 ios 上的照片应用程序一样?谢谢
    • 您还可以设置滚动视图的最大和最小比例属性以获取更多信息,请查看click here
    【解决方案2】:

    将您的 ImageView 缩放 contentMode 设置为 UIViewContentModeCenter 并在加载时缩小(如果需要)。当您准备好图像时,通过执行以下操作设置起始缩放比例:

            //Min scale is how much ever it takes to fit the image in the view
            CGRect scrollViewFrame = self.scrollView.frame;
            CGFloat scaleWidth = scrollViewFrame.size.width / self.imageView.image.size.width;
            CGFloat scaleHeight = scrollViewFrame.size.height / self.imageView.image.size.height;
            CGFloat minScale = MIN(scaleWidth, scaleHeight);
            self.scrollView.minimumZoomScale = minScale;
            self.scrollView.zoomScale = minScale;
    

    【讨论】:

    • 非常感谢它解决了我的问题。我正在使用 contentMode 比例来适应导致抖动效果。
    【解决方案3】:

    这是我发现的唯一完美无瑕的解决方案。它包括双击和两个手指手势来放大和缩小。 http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content

    【讨论】:

    • 接受您的回答,以便将来对其他人有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2012-11-24
    • 2012-02-12
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    • 2018-08-24
    • 2017-01-06
    相关资源
    最近更新 更多