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

加载网络图片reloadCellAtIndex方法触发三次问题 #197

Open
ETmanwenhan opened this issue Jan 19, 2021 · 6 comments
Open

加载网络图片reloadCellAtIndex方法触发三次问题 #197

ETmanwenhan opened this issue Jan 19, 2021 · 6 comments

Comments

@ETmanwenhan
Copy link

相册只要一张图片,但是加载网络图片reloadCellAtIndex方法触发三次问题。导致一张图片同时下载三次哦。怎么解决该问题呢?

屏蔽JXPhotoBrowser中viewDidLoad方法中的两行代码,就只会重复调用两次,请问这个问题怎么只控制调用一次呢?:

//        view.setNeedsLayout()
//        view.layoutIfNeeded()
@JiongXing
Copy link
Owner

谢反馈,我找时间看下

@ETmanwenhan
Copy link
Author

ETmanwenhan commented Jan 20, 2021

谢反馈,我找时间看下
问题解决了!!!
JXPhotoBrowser中的viewDidLoad方法调用browserView.reloadData(),只会调用一次reloadCellAtIndexJXPhotoBrowserView的reloadItems方法中需要调用cell.layoutIfNeeded()强制更新Cell布局!丝滑动画也正常。感谢🙏

调整的代码如下:

JXPhotoBrowser.m

    open override func viewDidLoad() {
        super.viewDidLoad()
        
        automaticallyAdjustsScrollViewInsets = false
        hideNavigationBar(true)
        
        browserView.photoBrowser = self
        transitionAnimator.photoBrowser = self
        
        view.backgroundColor = .clear
        maskView.frame = view.bounds
        browserView.frame = view.bounds
        view.addSubview(maskView)
        view.addSubview(browserView)
        
        browserView.didChangedPageIndex = { [weak self] index in
            guard let `self` = self else { return }
            self.pageIndicator?.didChanged(pageIndex: index)
            self.didChangedPageIndex(index)
        }
        
        view.setNeedsLayout()
        view.layoutIfNeeded()
        
        self.reloadData()
    }
    
    open override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        maskView.frame = view.bounds
        browserView.frame = view.bounds
        pageIndicator?.reloadData(numberOfItems: numberOfItems(), pageIndex: pageIndex)
    }
JXPhotoBrowserView.m

    open override func layoutSubviews() {
        super.layoutSubviews()
        print("====>>>layoutSubviews...")
        if scrollDirection == .horizontal {
            scrollView.frame = CGRect(x: 0, y: 0, width: bounds.width + itemSpacing, height: bounds.height)
        } else {
            scrollView.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + itemSpacing)
        }
        // reloadData()
    }

       /// 刷新所有Cell的数据
    open func reloadItems() {
        visibleCells.forEach { [weak self] index, cell in
            guard let `self` = self else { return }
            self.reloadCellAtIndex((cell, index, self.pageIndex))
            cell.setNeedsLayout()
            cell.layoutIfNeeded() // 调用该方法强制更新Cell布局
        }
        if let cell = visibleCells[pageIndex] {
            cellWillAppear(cell, pageIndex)
        }
    }

@TML007
Copy link

TML007 commented Feb 11, 2022

谢反馈,我找时间看下

不知道作者有时间修复这问题不?

@ETmanwenhan
Copy link
Author

ETmanwenhan commented Feb 11, 2022 via email

@shywoody
Copy link

shywoody commented Sep 7, 2022

相册只要一张图片,但是加载网络图片reloadCellAtIndex方法触发三次问题。导致一张图片同时下载三次哦。怎么解决该问题呢?

屏蔽JXPhotoBrowser中viewDidLoad方法中的两行代码,就只会重复调用两次,请问这个问题怎么只控制调用一次呢?:

//        view.setNeedsLayout()
//        view.layoutIfNeeded()

现在这个demo跑在iOS 15.5的模拟器上会出现滑动不到下一张图也无法滑动关闭, 楼主有遇到么?

@ioslhf
Copy link

ioslhf commented Dec 25, 2023

谢反馈,我找时间看下

请问一下大佬,这个问题解决了吗

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

5 participants