Giter Club home page Giter Club logo

Comments (10)

isandeepj avatar isandeepj commented on July 20, 2024 1

Hello @jams032

Here your queries feedback. I hope this helps you. Please let me know if any issue.

  1. centerFlowLayout.currentCenteredIndexPath to get currently selected indexpath
  2. centerFlowLayout.currentCenteredPage to get current selected page

from yzcenterflowlayout.

isandeepj avatar isandeepj commented on July 20, 2024 1

@jams032 you can do 2 way based on your requirement

  1. 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)")
        }
    }
  1. 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.

isandeepj avatar isandeepj commented on July 20, 2024 1

@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.

jams032 avatar jams032 commented on July 20, 2024

@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.

jams032 avatar jams032 commented on July 20, 2024

@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.

jams032 avatar jams032 commented on July 20, 2024

@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.

Screenshot 2020-11-12 at 8 00 41 AM

from yzcenterflowlayout.

jams032 avatar jams032 commented on July 20, 2024

@sandeep-yudiz , i found this from the implementation.
You are awesome, thanks for your support.

from yzcenterflowlayout.

isandeepj avatar isandeepj commented on July 20, 2024

@jams032
Most welcome!

from yzcenterflowlayout.

jams032 avatar jams032 commented on July 20, 2024

@sandeep-yudiz , any shortcut to do this ? Can we show multiple side item ?

Screenshot 2020-11-12 at 12 42 26 PM

from yzcenterflowlayout.

isandeepj avatar isandeepj commented on July 20, 2024

@jams032 sorry, not possible with the current code structure for following UI.


.

from yzcenterflowlayout.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.