放弹跳时不会更新UIScrollView的zoomScale属性

放弹跳时不会更新UIScrollView的zoomScale属性

本文介绍了缩放弹跳时不会更新UIScrollView的zoomScale属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我有一个不在UIScrollView之外的视图.由于许多原因,它不能简单地位于滚动视图内部.所以现在我正在做的是,随着UIScrollView的缩放/平移,我更新了其他辅助视图.我要考虑的唯一问题是,在视图弹回到最小或最大比例时,不调整zoomScale值.关于如何在动画返回时获取此值的任何建议?

Right now I have a view that is outside of the UIScrollView. For many reasons, it cannot be simply inside the scrollview. So right now what i'm doing is, as the UIScrollView is scaled/panned, I update my other auxiliary view. The only issue i'm coming into is, the zoomScale value is not adjusted for while the view is bouncing back to either the minimum or maximum scale. Any suggestions on how to obtain this value while it animates back?

示例代码:

self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, appSize.width, appSize.height)];
self.scrollView.contentSize = CGSizeMake(appSize.width * 2, appSize.height * 2);

self.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
self.scrollView.delegate = self;
self.scrollView.bounces = YES;
self.scrollView.bouncesZoom = YES;
self.scrollView.alwaysBounceHorizontal = YES;
self.scrollView.alwaysBounceVertical = YES;
self.scrollView.showsHorizontalScrollIndicator = YES;
self.scrollView.showsVerticalScrollIndicator = YES;

self.scrollViewZoomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
                                                                   appSize.width * 2,
                                                                   appSize.height * 2)];
[[self scrollView] addSubview:self.scrollViewZoomView];

float minZoomScale = 2.0f;

self.scrollView.minimumZoomScale = minZoomScale;
self.scrollView.maximumZoomScale = 1.0f;
self.scrollView.zoomScale = self.scrollView.minimumZoomScale;

然后是自我

-(void) scrollViewDidZoom:(UIScrollView *)scrollView {
    float scale = [scrollView zoomScale];
    [self updateAuxViewScale:scale];
}

推荐答案

感谢此答案,很明显可以使用 presentationLayer 获取正确的值.我创建了一个 UIScrollView category 来为 zoomScale contentOffset contentSize 添加特殊的吸气剂即使 UIScrollView 正在设置动画,该参数仍会返回正确的值.

Thanks to this answer it becomes clear that one can use the presentationLayer to get the correct values.I created a UIScrollView category to add special getters for zoomScale, contentOffset and contentSize which return the correct values even if the UIScrollView is animating.

您可以在此处找到该存储库: https://github.com/bddckr/BDDRScrollViewExtensions

You can find the repo here: https://github.com/bddckr/BDDRScrollViewExtensions

这篇关于缩放弹跳时不会更新UIScrollView的zoomScale属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:35