Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

How to get real contentSize? #52

Open
Ewg777 opened this issue Mar 28, 2019 · 9 comments
Open

How to get real contentSize? #52

Ewg777 opened this issue Mar 28, 2019 · 9 comments

Comments

@Ewg777
Copy link
Contributor

Ewg777 commented Mar 28, 2019

Hi,

Thanks for such a great lib!

How to get real height of the content without filling and so on?

Here is an example but it doesn't work properly with you lib. Do you have any idea? @gleue

class MyCollectionView: UICollectionView {
    // MARK: - Layout
    override func layoutSubviews() {
        super.layoutSubviews()

        let height = contentSize.height
        guard
            height > 1 else {
                return
        }
// here the height
    }
}

P.s. I'd like to use two instances of the lib on a page.

Regards,

@Ewg777
Copy link
Contributor Author

Ewg777 commented Mar 28, 2019

@gleue

@gleue
Copy link
Owner

gleue commented Mar 29, 2019

Did you mean the height of (overlapping) cards combined?

@Ewg777
Copy link
Contributor Author

Ewg777 commented Mar 29, 2019

2019-03-29_11-02-55
@gleue this one

@gleue
Copy link
Owner

gleue commented Mar 29, 2019

Have you tried collectionView.collectionViewLayout.collectionViewContentSize ?

@Ewg777
Copy link
Contributor Author

Ewg777 commented Mar 29, 2019

@gleue unfortunately, it's not public method. Also this method will always return self.collectionView.bounds


    if (contentSize.height < CGRectGetHeight(self.collectionView.bounds)) {

        contentSize.height = CGRectGetHeight(self.collectionView.bounds);

@gleue
Copy link
Owner

gleue commented Mar 29, 2019

Oops -- didn't look at the code ;-)

Sorry, then you'd probably have to determine it from your own version of TGLStackedLayout. Have a look at prepareLayout...

@Ewg777
Copy link
Contributor Author

Ewg777 commented Mar 29, 2019

@gleue right, I've made a workaround in TGLStackedLayout and TGLExposedLayout. It works for TGLExposedLayoutPinningModeNone.


- (void)prepareLayout {
    CGRect realContentSize = CGRectZero;
    for (NSInteger item = 0; item < itemCount; item++) {
...

        layoutAttributes[indexPath] = attributes;
        realContentSize = CGRectUnion(attributes.frame, realContentSize);
    }
    self.realContentSize = realContentSize;

    self.layoutAttributes = layoutAttributes;
}


Do you have a better solution?

@gleue
Copy link
Owner

gleue commented Mar 29, 2019

Elegant 👍

I don't have a better solution off the top of my head... Would have to think about it, but I am really busy at the moment, so it would take some time

@Ewg777
Copy link
Contributor Author

Ewg777 commented Mar 29, 2019

Great! Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants