Giter Club home page Giter Club logo

Comments (8)

mahesh789 avatar mahesh789 commented on July 27, 2024 1

from animatingtableviewheader.

johndelong avatar johndelong commented on July 27, 2024

Hi @mahesh789 ,

I have a couple questions for you that might help to identify what is going on in your situation :)

  1. Could you clarify what you mean by "estimate automatic"? Sounds like you are saying that it's disabled in my project but enabled in yours - but I'm not exactly sure what property you are referring to. Maybe a screenshot would help?

  2. When you reload your table view, are you inserting/deleting cells? Do you change the scroll position when you reload?

Also, as a side note, viewWillAppear may not be a great place for calling reloadData. I suppose it depends on your situation, but viewDidAppear may help a little in this specific scenario.

from animatingtableviewheader.

mahesh789 avatar mahesh789 commented on July 27, 2024

Please check your project in attachment file.
AnimatingTableViewHeader-master.zip

from animatingtableviewheader.

johndelong avatar johndelong commented on July 27, 2024

Thank you for the example project. I think i have a better idea of what is going on now.

You choose to size the cells using UITableViewAutomaticDimension (which maps to these checkboxes here)
image.

This in and of itself is not problematic, but I noticed that you also added the delegate method tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) and specified a hard coded height of 100. As a result, as the table view tries to size itself according to the UITableViewAutomaticDimension rules, it gives the cell only as much room (height wise) as it thinks the cell needs (in our case about 44 points). However, when it finally comes time to show the cell on the screen, your delegate method says, "No wait, I actually want the cell height to be 100 points!" As a result, the table view needs to resize itself and the scrollView.contentSize.height changes.

This cause our math in the scrollViewDidScroll(_ scrollView: UIScrollView) function to get messed up - specifically with the scrollDiff variable. Because the height of the scroll view changed, the diff becomes inflated since the difference from the previous scroll position to the current scroll position is larger (about 56 points larger! 56 + 44 = 100). Finally, as a result, we see the header becoming "bouncy" as we scroll up and down the page.

Although I wouldn't recommend using UITableViewAutomaticDimension AND setting the cell height to a specific value, you have pointed out an issue that is fixable in this example project. I'll update the code shortly and link back here the solution.

from animatingtableviewheader.

johndelong avatar johndelong commented on July 27, 2024

@mahesh789, I believe i've addressed your issue with the above commit. Specifically this line.

Let me know if you have any questions or if this didn't actually solve your issue.

Thanks!

from animatingtableviewheader.

mahesh789 avatar mahesh789 commented on July 27, 2024

from animatingtableviewheader.

mahesh789 avatar mahesh789 commented on July 27, 2024

from animatingtableviewheader.

Khanasif07 avatar Khanasif07 commented on July 27, 2024

if you reload only rows instead of complete section, issue will be resolved.
Just call this function with proper params like section old count and new count.

extension UITableView{

func reloadRowsInSection(section: Int, oldCount:Int, newCount: Int){
    
    let maxCount = max(oldCount, newCount)
    let minCount = min(oldCount, newCount)
    
    var changed = [IndexPath]()
    
    for i in minCount..<maxCount {
        let indexPath = IndexPath(row: i, section: section)
        changed.append(indexPath)
    }
    
    var reload = [IndexPath]()
    for i in 0..<minCount{
        let indexPath = IndexPath(row: i, section: section)
        reload.append(indexPath)
    }
    
    beginUpdates()
    if(newCount > oldCount){
        insertRows(at: changed, with: .fade)
    }else if(oldCount > newCount){
        deleteRows(at: changed, with: .fade)
    }
    if(newCount > oldCount || newCount == oldCount){
        insertRows(at: reload, with: .none)
    }
    endUpdates()
}

}

from animatingtableviewheader.

Related Issues (8)

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.