scroll not smooth while scroll small space and release your hand quickly
Beyond-Chao opened this issue · 10 comments
scroll not smooth while scroll small space and release your hand quickly
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.
thanks!Let me try
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.
Unfortunately this is not working for me. Does anyone have any other solution?
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
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()
}
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`
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
Can anyone help as I am unable to fix this issue? and I have used pod for the same.
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