UPCarouselFlowLayout icon indicating copy to clipboard operation
UPCarouselFlowLayout copied to clipboard

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

Open Beyond-Chao opened this issue 7 years ago • 10 comments

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

Beyond-Chao avatar Jun 15 '18 08:06 Beyond-Chao

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.

iamsanketray123 avatar Jul 11 '18 08:07 iamsanketray123

thanks!Let me try

Beyond-Chao avatar Jul 12 '18 02:07 Beyond-Chao

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.

gk704297 avatar Aug 08 '18 12:08 gk704297

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

Sulinskii avatar Oct 25 '18 11:10 Sulinskii

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

MrFuFuFu avatar Nov 09 '18 00:11 MrFuFuFu

@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() }

suraj-ios avatar Feb 22 '19 04:02 suraj-ios

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`

santaasus avatar Apr 25 '19 10:04 santaasus

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

petr-fiala avatar Feb 25 '20 12:02 petr-fiala

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

ghost avatar Apr 26 '20 04:04 ghost

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

petr-fiala avatar Apr 26 '20 09:04 petr-fiala