缩放 - 弹跳时,UIScrollView的zoomScale属性不会更新 [英] The zoomScale property of UIScrollView isn't updated while zoom-bouncing

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

问题描述

现在我有一个超出UIScrollView的视图。由于许多原因,它不能简单地在scrollview中。所以现在我正在做的是,当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 类别来为 zoomScale contentOffset contentSize 即使 UIScrollView <返回正确的值/ code>是动画。

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属性不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆