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

scroll not smooth while scroll small space and release your hand quickly #37

Open
Beyond-Chao opened this issue Jun 15, 2018 · 10 comments

Comments

@Beyond-Chao
Copy link

scroll not smooth while scroll small space and release your hand quickly

@iamsanketray123
Copy link

Yes this issue exists. Please fix. The animation isn't smooth when we try to scroll but it stop scrolling the very next instant. It leads to a jerk effect. Maybe you need to fix your snapping code. Adding 0.1-0.2 seconds of more animation time.

@Beyond-Chao
Copy link
Author

thanks!Let me try

@gk704297
Copy link

gk704297 commented Aug 8, 2018

Hi guys, i found solution for this problem. Just Replace this code in targetContentOffset method

let proposedContentOffsetCenterOrigin = (isHorizontal ? proposedContentOffset.x + 1000 * velocity.x : proposedContentOffset.y + 1000 * velocity.y) + midSide

thanks.

@Sulinskii
Copy link

Unfortunately this is not working for me. Does anyone have any other solution?

@MrFuFuFu
Copy link

MrFuFuFu commented Nov 9, 2018

Or try to change it to int targetContentOffset method

let proposedContentOffsetCenterOrigin = (isHorizontal ? proposedContentOffset.x + (proposedContentOffset.x * velocity.x) : proposedContentOffset.y + (proposedContentOffset.y * velocity.y)) + midSide

@suraj-ios
Copy link

@Beyond-Chao

You can try this code.

override func viewDidLayoutSubviews() {
self.setupLayout()
if self.indexNumber == 0{ // Set indexNumber = 0 for the 1st cell only.
let layout = UPCarouselFlowLayout()
layout.itemSize = CGSize(width:view.frame.width, height:448)
layout.scrollDirection = .horizontal
self.collectionView.collectionViewLayout = layout
}
self.rotationDidChange()
}

@santaasus
Copy link

santaasus commented Apr 25, 2019

I resolved the problem let differenceBetweenOffsets = velocity.x > 0 ? targetContentOffset.x - prevOffset : prevOffset - targetContentOffset.x

   ` let jerkEffect = prevOffset == targetContentOffset.x || // Didn't move anywhere
                        targetContentOffset.x =< 0 || // Didn't move anywhere
                                differenceBetweenOffsets < 100 // had difference offsets between prev and current, but not enough for scroll by the next item `

  `  if jerkEffect {
        print("Ops occurred jerk effect")
        let correctOffset = velocity.x > 0 ? targetContentOffset.x + itemSize.width + self.minimumLineSpacing
                                            : targetContentOffset.x - itemSize.width - self.minimumLineSpacing
        targetContentOffset.x = correctOffset
    }
    prevOffset = targetContentOffset.x`

@petr-fiala
Copy link

I resolved the problem let differenceBetweenOffsets = velocity.x > 0 ? targetContentOffset.x - prevOffset : prevOffset - targetContentOffset.x

   ` let jerkEffect = prevOffset == targetContentOffset.x || // Didn't move anywhere
                        targetContentOffset.x =< 0 || // Didn't move anywhere
                                differenceBetweenOffsets < 100 // had difference offsets between prev and current, but not enough for scroll by the next item `

  `  if jerkEffect {
        print("Ops occurred jerk effect")
        let correctOffset = velocity.x > 0 ? targetContentOffset.x + itemSize.width + self.minimumLineSpacing
                                            : targetContentOffset.x - itemSize.width - self.minimumLineSpacing
        targetContentOffset.x = correctOffset
    }
    prevOffset = targetContentOffset.x`

works on iOS13,
also you should update prevOffset in viewDidLayoutSubviews, to make it work right after initialization and rotation

@ghost
Copy link

ghost commented Apr 26, 2020

Can anyone help as I am unable to fix this issue? and I have used pod for the same.

@petr-fiala
Copy link

Can anyone help as I am unable to fix this issue? and I have used pod for the same.

i also added extra condition for jerkEffect

        // jerk effect fix
        let layout = carouselCollectionView.collectionViewLayout as! UPCarouselFlowLayout
        let differenceBetweenOffsets = velocity.x > 0 ? targetContentOffset.pointee.x - prevOffset : prevOffset - targetContentOffset.pointee.x
        let jerkEffect = (prevOffset == targetContentOffset.pointee.x || // Didn't move anywhere
            targetContentOffset.pointee.x <= 0 || // Didn't move anywhere
            differenceBetweenOffsets < 100) && // had difference offsets between prev and current, but not enough for scroll by the next item `
            abs(velocity.x) > 0.1
        if jerkEffect {
            print("Ops occurred jerk effect")
            let correctOffset = velocity.x > 0 ? targetContentOffset.pointee.x + layout.itemSize.width + layout.minimumLineSpacing : targetContentOffset.pointee.x - layout.itemSize.width - layout.minimumLineSpacing
            targetContentOffset.pointee.x = correctOffset
        }
        prevOffset = targetContentOffset.pointee.x

also, don't forget to update prevOffset whenever you manually set the offset and during initialization

yyjim added a commit to cardinalblue/UPCarouselFlowLayout that referenced this issue Nov 10, 2022
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

8 participants