Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

超过屏幕高度的网络图片,双指缩放然后复原大小后,手势下拉无法关闭 #201

Open
yanmingLiu opened this issue Mar 5, 2021 · 9 comments

Comments

@yanmingLiu
Copy link

demo中Kingfisher 加载示例中 KingfisherImageViewController:

修改图片源地址为长图: let url = URL(string: "https://ewow-community.epal.gg/data/IdfF31E0/community/1614666157363137079773003777.png")

双指放大图片

缩小图片到原始状态

下拉, 无法关闭!!!

@JiongXing
Copy link
Owner

我查下

@yanmingLiu
Copy link
Author

我查下

问题在缩放图片后, scrollView.contentOffset.y > 0: 代码问题如下:

// 向下滑动,如果图片顶部超出可视区域,不响应手势
if scrollView.contentOffset.y > 0 {
print("向下滑动,scrollView.contentOffset.y = (scrollView.contentOffset.y) ")
return false
}

@yanmingLiu
Copy link
Author

yanmingLiu commented Mar 5, 2021

我查下

scrollViewDidZoom中,只计算了imageView.center = computeImageLayoutCenter(in: scrollView), 是否也需要添加判断图片frame, 如果复原了,也得把scrollView.contentOffset复原

computeImageLayoutCenter中打印如下:
scrollView.contentOffset = (0.0, 22.666666666666668), 缩放结束后,scrollView.contentOffset变了,所以向下滑动,不响应手势

@JiongXing
Copy link
Owner

好的,今天好忙,我晚些时候看

@yanmingLiu
Copy link
Author

好的,今天好忙,我晚些时候看

我提交了一个pr

@JiongXing
Copy link
Owner

收到

@JiongXing
Copy link
Owner

在恢复原比例时,把scrollView.contentOffset = .zero,会影响交互,突然闪到图片顶部,不一定好。其实手势下拉还是可以关闭的,但是要分两步,第一步滑回顶部,第二步要等滑动停下来后再下拉就可以了

@JiongXing
Copy link
Owner

我刚刚看了微信朋友圈长图下拉,它不用等滑动停下就可以下拉关闭,这个细节应该是特别优化处理了,也许我也可以实现一下

@yanmingLiu
Copy link
Author

我刚刚看了微信朋友圈长图下拉,它不用等滑动停下就可以下拉关闭,这个细节应该是特别优化处理了,也许我也可以实现一下

那在手势处理那就要改变一下判断,不应该简单的由contentOffset.y 来判断,YBImageBrowser的处理如下,可以借鉴一下:
else if (pan.state == UIGestureRecognizerStateCancelled || pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateRecognized || pan.state == UIGestureRecognizerStateFailed) {

    // End.
    if (_interacting) {
        CGPoint velocity = [pan velocityInView:self.imageScrollView];
        
        BOOL velocityArrive = ABS(velocity.y) > profile.dismissVelocityY;
        BOOL distanceArrive = ABS(point.y - _interactStartPoint.y) > containerSize.height * profile.dismissScale;
        
        BOOL shouldDismiss = distanceArrive || velocityArrive;
        if (shouldDismiss) {
            [self hideBrowser];
        } else {
            [self restoreInteractionWithDuration:profile.restoreDuration];
        }
    }
    
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants