Comments (1)
Finally, I got this solution to work.
define the value
let originY: CGFloat = 0
let floatingSectionOriginY = collectionView.contentOffset.y
If scrolling up use value from contentOffset.y to keep row is floating.
var selectedOriginY = originY
if floatingSectionOriginY >= originY {
selectedOriginY = floatingSectionOriginY
}
Full code
override func prepare() {
guard delegate != nil,
let collectionView = collectionView,
collectionView.numberOfSections > 0
else { return }
if itemAttributes.count != collectionView.numberOfSections {
generateItemAttributes(collectionView: collectionView)
return
}
let originY: CGFloat = 0
let floatingSectionOriginY = collectionView.contentOffset.y
let originX: CGFloat = 0
let floatingSectionOriginX = collectionView.contentOffset.x
for section in 0..<collectionView.numberOfSections {
for item in 0..<collectionView.numberOfItems(inSection: section) {
if section >= delegate.numberOfFirstRowFloat()
&& item >= delegate.numberOfFirstColumnFloat() {
continue
}
let attributes = layoutAttributesForItem(at: IndexPath(item: item, section: section))!
if section < delegate.numberOfFirstRowFloat() {
var selectedOriginY = originY
if floatingSectionOriginY >= originY {
selectedOriginY = floatingSectionOriginY
}
var frame = attributes.frame
let size = itemsSize[item]
frame.origin.y = selectedOriginY + (size.height * CGFloat(section))
attributes.frame = frame
}
if item < delegate.numberOfFirstColumnFloat() {
var selectedOriginX = originX
if floatingSectionOriginX >= originX {
selectedOriginX = floatingSectionOriginX
}
var frame = attributes.frame
let prevItem = item - 1
if prevItem < 0 {
frame.origin.x = selectedOriginX
} else {
let size = itemsSize[prevItem]
frame.origin.x = selectedOriginX + (size.width * CGFloat(item))
}
attributes.frame = frame
}
}
}
}
from customcollectionviewlayout.
Related Issues (20)
- Crash on return 0 from numberOfSectionsInCollectionView(_)
- Scrolling Collection View causes the cell content to disappear
- Swift3 HOT 5
- Collectionview Cell spacing
- can i use selection method for particular whole row?
- PrepareLayout section variable unidentified
- Stick last section to the bottom
- Stop Diagonal Scroll
- Collection View is not working at all
- Vertical Line after the Sticky Column?
- reloadData does NOT work HOT 6
- Does anyone see a solution here to make a swipe to delete for an entire row?
- How can i perfom item selection on collection view? HOT 1
- Dynamic rows or columns HOT 2
- How to increase the section height according to the text.
- How to increase the height automatically according to the text
- Dynamic row HOT 1
- Crashing HOT 3
- How to print the data for content label from different arrays
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from customcollectionviewlayout.