Ste*_*ter 22 iphone objective-c uiscrollview ios
现在我有一个超出UIScrollView的视图.由于许多原因,它不能简单地在scrollview中.所以我现在正在做的是,当UIScrollView被缩放/平移时,我更新了我的其他辅助视图.我遇到的唯一问题是,当视图重新回到最小或最大比例时,不会调整zoomScale值.有关如何在动画效果时获取此值的任何建议吗?
示例代码:
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;
Run Code Online (Sandbox Code Playgroud)
然后是自我
-(void) scrollViewDidZoom:(UIScrollView *)scrollView {
float scale = [scrollView zoomScale];
[self updateAuxViewScale:scale];
}
Run Code Online (Sandbox Code Playgroud)
缩放的反弹是动画,因此zoomScale即使动画仍在运行,属性也会立即成为动画的目标值.如果您想将滚动视图所具有的缩放比例应用于另一个视图,则可以使用以下方法检索它:
-scrollViewDidScroll:检查内容是否视图具有动画.这种方法并不优雅,但它确实有效.以下是一些可以帮助您入门的代码:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat zoomScale = _scrollView.zoomScale;
CALayer *layer = _contentView.layer;
NSArray *animationKeys = [layer animationKeys];
if (animationKeys.count == 0) {
// set zoomScale on target view
} else {
CFTimeInterval duration = 0.0;
for (NSString *animationKey in animationKeys) {
CAAnimation *animation = [layer animationForKey:animationKey];
duration = animation.duration;
break;
}
// easeInEaseOut is the default animation when the zoom bounces
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
// set zoomScale on target view
} completion:nil];
}
}
Run Code Online (Sandbox Code Playgroud)
由于这个答案,很明显可以使用它presentationLayer来获得正确的值.我创建了一个UIScrollView category为其添加特殊的getter zoomScale,contentOffset并且contentSize即使UIScrollView是动画也会返回正确的值.
你可以在这里找到回购:https://github.com/bddckr/BDDRScrollViewExtensions
| 归档时间: |
|
| 查看次数: |
7482 次 |
| 最近记录: |