JiongXing / PhotoBrowser

Elegant photo browser in Swift. 图片与视频浏览器。
MIT License
1.31k stars 206 forks source link

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

Open yanmingLiu opened 3 years ago

yanmingLiu commented 3 years ago

demo中Kingfisher 加载示例中 KingfisherImageViewController:

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

双指放大图片

缩小图片到原始状态

下拉, 无法关闭!!!

JiongXing commented 3 years ago

我查下

yanmingLiu commented 3 years ago

我查下

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

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

yanmingLiu commented 3 years ago

我查下

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

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

JiongXing commented 3 years ago

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

yanmingLiu commented 3 years ago

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

我提交了一个pr

JiongXing commented 3 years ago

收到

JiongXing commented 3 years ago

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

JiongXing commented 3 years ago

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

yanmingLiu commented 3 years ago

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

那在手势处理那就要改变一下判断,不应该简单的由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];
        }
    }

}