Giter VIP home page Giter VIP logo

Comments (8)

alexookah avatar alexookah commented on May 15, 2024 1

@MaherKSantina
this issue can be closed

from mspeekcollectionviewdelegateimplementation.

MaherKSantina avatar MaherKSantina commented on May 15, 2024

Thanks @ssamkough for contributing to this repo by raising this issue!
I was wondering are you using the latest version of the library?
If yes, can you try this for me:
Print out the frame width for the peeking collection view and see if it's the same as the device's frame. I can see that the scrolling doesn't work for the subsequent collection items as they are cut off and not shown in center properly.
Seems that the calculation of the offset of items is not correct
The ideal case for me would be if you're able to share with me a minimal example project that has the issue, this way I'm able to investigate it properly and work on a fix

from mspeekcollectionviewdelegateimplementation.

ssamkough avatar ssamkough commented on May 15, 2024

I am using version 3.1.1.

I will print the values and tell you what I see. In the meantime, here is an example of my project:

import MSPeekCollectionViewDelegateImplementation
class FeedController: UITableViewController {
    var posts = [Post]()
    var behavior: MSCollectionViewPeekingBehavior!

    override func tableView(_ tableView: UITableView,
                            willDisplay cell: UITableViewCell,
                            forRowAt indexPath: IndexPath) {
        behavior = MSCollectionViewPeekingBehavior(cellSpacing: 15)
        cell.taggedProductsCollectionView.configureForPeekingBehavior(behavior: behavior)
        cell.taggedProductsCollectionView.delegate = self
        cell.taggedProductsCollectionView.dataSource = self
    }

    override func scrollViewWillEndDragging(_ scrollView: UIScrollView,
                                            withVelocity velocity: CGPoint,
                                            targetContentOffset: UnsafeMutablePointer<CGPoint>) {
            behavior.scrollViewWillEndDragging(scrollView,
                                               withVelocity: velocity,
                                               targetContentOffset: targetContentOffset)
    }
}

extension FeedController: UICollectionViewDataSource,
                          UICollectionViewDelegate,
                          UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return posts[collectionView.tag].taggedProducts.count
    }

    func collectionView(_ collectionView: UICollectionView,
                        cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        guard let cell = collectionView.dequeueReusableCell(
            withReuseIdentifier: "taggedProductCell",
            for: indexPath) as? TaggedProductCell else {
                fatalError("Unexpected index path, problem dequeuing resuable cell.")
            }
        let taggedProduct = self.posts[collectionView.tag].taggedProducts[indexPath.item]
        cell.taggedProduct = taggedProduct
        cell.taggedProductDelegate = self
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let taggedProduct = self.posts[collectionView.tag].taggedProducts[indexPath.item]
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 10
        collectionView.scrollToItem(at: indexPath, at: .bottom, animated: false)
        layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
        collectionView.setCollectionViewLayout(layout, animated: false)
    }
}

from mspeekcollectionviewdelegateimplementation.

ssamkough avatar ssamkough commented on May 15, 2024

Print out the frame width for the peeking collection view and see if it's the same as the device's frame. I can see that the scrolling doesn't work for the subsequent collection items as they are cut off and not shown in center properly.

By the peeking collection view do you mean the collection view, or just the peeking part of it? Because the collection view is the same size as the device (using constraints), but each item has a custom width of 373. This is all configured within a storyboard.

from mspeekcollectionviewdelegateimplementation.

MaherKSantina avatar MaherKSantina commented on May 15, 2024

Hey @ssamkough really sorry I didn't receive a Github notification for your comments 😢 Okay so let's do a little debugging. Can you try to move the whole collection view outside the cell? Like have it directly in the view controller? I'm expecting that having the collection view inside a table view cell will cause the frames not to be calculated properly. If the collection view behaves properly there, then I think you might need to initialize the peeking and everything in the viewDidLayoutSubviews function. This way we're sure that the frame calculations are all done by then
Hope that helps, especially that it's 20 days late 😢

from mspeekcollectionviewdelegateimplementation.

alexookah avatar alexookah commented on May 15, 2024

Hello @MaherKSantina
I am also experiencing the same issue.
I have a collectionView inside UITableViewHeaderFooterView.
When using cellPeekWidth the scroll calculations are wrong. If set to 0 the scrolling is correct.
I tried to put the initialize of the behaviour inside layoutSubviews()
I even tried to set the collectionViewFrameWidth same as the device's width before creating the behaviour
collectionView.frame.size.width = UIScreen.main.bounds.width
in order to have correct calculations, but that didn't help either.

from mspeekcollectionviewdelegateimplementation.

alexookah avatar alexookah commented on May 15, 2024

@MaherKSantina
here you can find my example implementation:
https://github.com/alexookah/MSPeekCollectionView-Example

from mspeekcollectionviewdelegateimplementation.

alexookah avatar alexookah commented on May 15, 2024

I resolved the issue @ssamkough @MaherKSantina.

If the collectionView is inside a tableview it needs:
collectionView.isPagingEnabled = false

Something similar exists in UICollectionView+PeekConfiguration.swift:
collectionView.configureForPeekingDelegate()

from mspeekcollectionviewdelegateimplementation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.