Giter Site home page Giter Site logo

Comments (9)

gskbyte avatar gskbyte commented on June 11, 2024

Hi,

maybe you can hack it like this: compute the ideal height for one line and then, every time the content of that label changes, set the contentHeight of the header view to be contentHeightForOneLineHeight + labelHeightForOneLine - currentLabelHeight.

from gskstretchyheaderview.

annjawn avatar annjawn commented on June 11, 2024

So my Xib's class calls an API to load the data into it's subviews and obviously that call is asynchronous. Which means that I might still be receiving data while the tableView.addSubview(header) already get's executed in my viewcontroller. Prior to using this library, I was using the same Xib to load into the tableView's tableHeaderView and once added there I would trigger a re-layout on the tableHeaderView which would re-size everything appropriately using the label's sizeToFit() and layoutIfNeeded(), and it works great. However, the same approach isn't working here. GSKStretchyHeaderView doesn't seem to be using the tableView's tableHeaderView so can you tell me how I can access the stretchyHeaderView's view once it's added onto the tableView?

Also, will setting the maximumContentHeight after the header is added to the tableview work? (so far it doesn't seem like it does). So even if I were to somehow calculate the label line height as you suggest, that calculation would be completely pointless if I am unable to assign it to the maximumContentHeight. What is really needed for this to work is somehow being able to trigger another layout pass perhaps using a delegate. The other way would really be to simply remove and re-add the headerview again, but I need to test this theory.

I really want this library to work for me but all the headers in my app have dynamic content as I explain above so it's going to be really difficult to use this without ugly hacks.😥

from gskstretchyheaderview.

gskbyte avatar gskbyte commented on June 11, 2024

Hi,

well, you will need to keep a reference to the header view in the view controller or wherever. When you change the maximumContentHeight, you may want to check if you are at the top of the table view, and then scrollToTop() manually.

I would try experimenting with some user-triggered height change, like tapping some button that adds text synchronously to your label in order to test this approach. Once you get it to work, you may add your code reacting to asynchronous calls.

from gskstretchyheaderview.

annjawn avatar annjawn commented on June 11, 2024

Yes. The table is at its original position when I try to change the maximumContentHeight. I will try your suggestion in my dev environment today.

from gskstretchyheaderview.

annjawn avatar annjawn commented on June 11, 2024

@gskbyte so here is what I found. With a button which adds 10 pts to the maximumContentHeight, the height gets increased but it only takes affect if I drag the tableview/scrollview down and release. I tried firing a layout pass after adding on to the maximumContentHeight but it didn't work.

from gskstretchyheaderview.

annjawn avatar annjawn commented on June 11, 2024

OK I think I found something that does work (somewhat). I was able to expand the header using stretchyHeader.setMaximumContentHeight(300, resetAnimated: true). The 300 is just a static hard coded value but my next step is to find the custom UIView's final height after all data has been populated.

from gskstretchyheaderview.

annjawn avatar annjawn commented on June 11, 2024

Alright, I give up. It won't work in this scenario, i.e. if the header view XIB has dynamic content especially in a stackview and uses autolayout. I think if we get the capability of doing tableView.tableHeaderView = stretchyHeader instead of tableView.addSubview(stretchyHeader) then the tableview will respect the autolayout inside of the header XIB + we can then easily trigger a layout pass and utilize setMaximumContentHeight to resize the header (i tried assigning to tableHeaderView but it didn't work).

With the current addSubView method there is no way to determine the height from the XIB, the only way it could work if I set translatesAutoresizingMaskIntoConstraints of the stretchy header to false and then have to manually add constraints which could get very ugly very quickly. 🙁

from gskstretchyheaderview.

gskbyte avatar gskbyte commented on June 11, 2024

Well, if the only thing changing the height of the header view is the amount of text, then you can use that every time the height changes to set the maximumContentHeight manually...

from gskstretchyheaderview.

annjawn avatar annjawn commented on June 11, 2024

Yes that's how I finally ended up doing. Calculate the label height using the boundingRect and then adding (or removing) the offset to the default header height using setMaximumContentHeight. It's working perfectly.

from gskstretchyheaderview.

Related Issues (20)

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.