Would be nice if AQGridView implemented sizeThatFits
It would be nice if AQGridView implemented sizeThatFits - I have an "Expander" view that will give a subview as much room as it can and uses sizeThatFits to try to do that. I tried the following (not pretty, but it works) and got the desires result:
// CHANGED: for clients that use this
- (CGSize)sizeThatFits:(CGSize)size { [_gridData gridViewDidChangeBoundsSize:size]; CGSize sizeThatFits = [_gridData sizeForEntireGrid]; [_gridData gridViewDidChangeBoundsSize:self.bounds.size]; return sizeThatFits; } // CHANGED: end changes
I am guessing that this will be hard because the grid view contains several other views. Unlike a text label which only contains one piece of content, the grid view can potentially contain hundreds or thousands of pieces of content.
OTOH, I was thinking of this (not considering many edge cases):
- (CGSize) sizeThatFits:(CGSize)aSize {
CGSize usableSize = (CGSize){
aSize.width - self.leftContentInset - self.rightContentInset,
aSize.height
};
CGSize tileSize = (CGSize) { /* … */ };
if (usableSize.width <= tileSize.width)
return aSize;
if (usableSize.height <= tileSize.height)
return aSize;
return (CGSize) {
usableSize.width - (usableSize.width % tileSize.width),
usableSize.height - (usableSize.height % tileSize.height)
};
}
My main concern with changing _gridData is that it might cause calculated results to be thrown away, making the entire operation potentially very costly. :/ And touching all the data might also be very costly, so the only cheap alternative is to cut corners and estimate.
On Oct 28, 2011, at 6:13 AM, jonruiz wrote:
It would be nice if AQGridView implemented sizeThatFits - I have an "Expander" view that will give a subview as much room as it can and uses sizeThatFits to try to do that. I tried the following (not pretty, but it works) and got the desires result:
// CHANGED: for clients that use this
- (CGSize)sizeThatFits:(CGSize)size { [_gridData gridViewDidChangeBoundsSize:size]; CGSize sizeThatFits = [_gridData sizeForEntireGrid]; [_gridData gridViewDidChangeBoundsSize:self.bounds.size]; return sizeThatFits; } // CHANGED: end changes
Reply to this email directly or view it on GitHub: https://github.com/AlanQuatermain/AQGridView/issues/94