Giter Club home page Giter Club logo

Comments (3)

Andrew05 avatar Andrew05 commented on June 5, 2024 1

This is incredible. Thanks for the help. I was very stuck trying to modify things around but this made it very clear. I really appreciate this!

from verticalcardswiper.

JoniVR avatar JoniVR commented on June 5, 2024 1

No problem, I've been in your situation, it's not easy to implement bug-free cell based paging. Glad it helped. I'm going to close the issue for now, let me know if you still need any help (you can always reopen it).

from verticalcardswiper.

JoniVR avatar JoniVR commented on June 5, 2024

Hi @Andrew05,

This functionality is probably not going to be implemented in the near future since it would require a lot of rewriting and I'd rather get some other things fixed first.

Normally if you switch up the X and Y values you should be able to get the same results on the horizontal axis instead of vertical but you need to make sure you account for all insets etc.

I posted my solution for vertical paging in the following stackoverflow thread:
https://stackoverflow.com/questions/13492037/targetcontentoffsetforproposedcontentoffsetwithscrollingvelocity-without-subcla/49617263#49617263

I suggest you look at all the answers in this thread as most of them are meant for horizontal paging. You should be able to easily find a good solution that fits your needs there.

Hope this helps. Let me know if you still need help.

Best regards,
Joni

edit 1: If you'd still like to use this library with your own paging algorithm I suggest you just download the Source folder from github, drag it into your project and then change the contents of the targetContentOffsetForProposedContentOffset:withScrollingVelocity function.

edit 2: After further looking into it, it looks like you'll need to change quite some things up to achieve a good result. I'd suggest you just use a UICollectionView and build your own solution with that, you can still look into how exactly I did things and make it suit your needs.

Here's the paging function which I got working horizontally in this project:

// Cell paging
internal override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
        
    // If the property `isPagingEnabled` is set to false, we don't enable paging and thus return the current contentoffset.
    guard isPagingEnabled else {
        let latestOffset = super.targetContentOffset(forProposedContentOffset: proposedContentOffset, withScrollingVelocity: velocity)
        return latestOffset
    }
        
    // Page width used for estimating and calculating paging.
    let pageWidth = cellWidth + self.minimumLineSpacing

    // Make an estimation of the current page position.
    let approximatePage = self.collectionView!.contentOffset.x/pageWidth
        
    // Determine the current page based on velocity.
    let currentPage = (velocity.x < 0.0) ? floor(approximatePage) : ceil(approximatePage)
        
    // Create custom flickVelocity.
    let flickVelocity = velocity.x * 0.3
        
    // Check how many pages the user flicked, if <= 1 then flickedPages should return 0.
    let flickedPages = (abs(round(flickVelocity)) <= 1) ? 0 : round(flickVelocity)
        
    // Calculate newVerticalOffset.
    let newHorizontalOffset = ((currentPage + flickedPages) * pageWidth) - self.collectionView!.contentInset.left

    return CGPoint(x: newHorizontalOffset, y: proposedContentOffset.y)
}

Here's a semi-working version, you'll probably need to change up quite a few things, I tried to mark everything that I changed up or probably still needs to be changed up with // CUSTOM comments:
VerticalCardSwiper-master.zip

But I'd suggest you just start with a UICollectionView from scratch and just use the paging algorithm. Also, I used the minimumLineSpacing which means I'm still using rows, but I think you'd be better of using minimumInterItemSpacing and setting sections instead of rows. Hope this helps.

from verticalcardswiper.

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.