Comments (10)
Hello @jams032
Here your queries feedback. I hope this helps you. Please let me know if any issue.
centerFlowLayout.currentCenteredIndexPath
to get currently selected indexpathcenterFlowLayout.currentCenteredPage
to get current selected page
from yzcenterflowlayout.
@jams032 you can do 2 way based on your requirement
- If you continue to track which current(center) indexPath then use scroll view did scroll delegate method. This method continues to called when you scroll left or right.
// any offset changes on called
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let indexPath = centerFlowLayout.currentCenteredIndexPath {
print("Current indexPath: \(indexPath)")
}
}
- After scrolling end with left or right then you can use the scroll view did end decelerating delegate method. This method not a continuous called on scrolling left or right.
// called when scroll view grinds to a halt
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if let indexPath = centerFlowLayout.currentCenteredIndexPath {
print("Current indexPath: \(indexPath)")
}
}
from yzcenterflowlayout.
@jams032 you can use scrollToPage(atIndex index: Int, animated: Bool = true)
method to scroll a specific index. I hope this helps you. Please let me know if any issue.
let index = array.count/2
collectionView.performBatchUpdates(nil) { [weak self] (isLoded) in
guard let weakSelf = self, isLoded else { return}
weakSelf.centerFlowLayout.scrollToPage(atIndex: index, animated: true)
}
from yzcenterflowlayout.
@sandeep-yudiz Say, i am in the viewcontroller class now. From where i can called this ? Any place to call it in viewcontroller class when user is scrolling the collectionview ?
from yzcenterflowlayout.
@sandeep-yudiz, applying the code in viewcontroller, i got the changed index after scroll finish :
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if let cIndexPath = centerFlowLayout.currentCenteredIndexPath {
print("\(cIndexPath)")
}
}
Do you think this is the only correct way ?
from yzcenterflowlayout.
@sandeep-yudiz yeah, i got it. Thank you so much for nice reply. I prefer using scrollViewDidEndDecelerating method because it is called at the end. scrollViewDidScroll is called so many times while scrolling, so i should not update UI so many times. Another query to you:
In the first load, we just load the collectionview with array elements. It set first item in the center. How i can set another index(may be middle item, index will be array.count/2) manually in the first load. Viewing the items from both sided will look nice in the first on viewcontroller, that's why i want to do it. Any way to set middle item in the first load ?
Thank you again.
from yzcenterflowlayout.
@sandeep-yudiz , i found this from the implementation.
You are awesome, thanks for your support.
from yzcenterflowlayout.
@jams032
Most welcome!
from yzcenterflowlayout.
@sandeep-yudiz , any shortcut to do this ? Can we show multiple side item ?
from yzcenterflowlayout.
@jams032 sorry, not possible with the current code structure for following UI.
from yzcenterflowlayout.
Related Issues (2)
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 yzcenterflowlayout.