-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example code for box reuse / offscreen culling with MGBoxProvider #116
Comments
This functions the same as UITableView cell reuse, but with a less awkward API and less code requirements. Why Block Properties Instead of ProtocolsThe use of block properties is optional, and you could instead subclass The Required BlocksboxMakerShould return fresh boxes without customisation. It could be as simple as boxCustomiserThis block is given a boxSizerThis should return the size, including margins, of a box at a given index. If all your boxes/rows/whatevers are the same size for the entire table/grid, then the answer is easy. In my example code you can see that boxCounterSimilar to UITableViewDataSource's |
To initialise the table/grid, you should call - (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.scroller];
[self fetchPerformers];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orient
duration:(NSTimeInterval)duration {
[self.scroller layout];
}
- (void)fetchPerformers {
self.performers = [TheInternet getTheThings];
[self.scroller layout];
} |
As of 3.2.0 boxes will now have their
|
Something that's missing from the above examples is how to cope with the underlying data changing. // get fresh data from the internets
self.performers = [TheInternet getTheThings];
// update the table after data change
[self.scroller layout];
// or alternatively, do it animated
[self.scroller layoutWithDuration:0.3 completion:nil]; Which is roughly equivalent to calling |
New optional block properties on @property (nonatomic, copy) MGBoxAnimator appearAnimation;
@property (nonatomic, copy) MGBoxAnimator disappearAnimation;
@property (nonatomic, copy) MGBoxAnimator moveAnimation; typedef void (^MGBoxAnimator)(id box, NSUInteger index, NSTimeInterval duration,
CGRect fromFrame, CGRect toFrame); They are responsible for doing their own UIView animation blocks, and responsible for setting the final frame, if appropriate. The For Note that this hasn't been tagged with a release number or pushed upstream to CocoaPods yet, so is only available if you're pulling directly from |
I can't quite make heads or tails of how this sits together, is there any chance of updating the demo app to use proper cell reuse? What's SGPadPerformerCell? I can't get this working with my own cells. |
There is a good chance of the demo app getting updated to show this, yes. It's high on my todo list. But I can't say when that'll happen.
|
Hey sobri909. First off, great work on this! It's been a pleasure to use so far. I have the above implemented and everything is working great. The only issue that i'm having is that my MGBoxes are stuck with a fixed width and height. My boxes can be different sizes, and I can't seem to figure out how to implement it using the box provider. Please help? Thanks! |
@m4rcoperuano Great to hear!
There's some newer bits in MGBoxProvider that allow for this. The CocoaDocs have the full details. The bits to look for are boxSizeMaker, boxMaker, and boxCustomiser. Also boxMarginMaker for if you want different margins for different boxes. Oh, I just noticed a typo in the docs for
Is actually meant to say:
Anyway, there's two points at which you set box sizes. The first is in The example code shows how to deal with differing header rows and content rows, but you can use any number of box types, and can also differ the box sizes independent of box type. |
Thanks! boxSizeMaker did the trick |
I'm throwing some working example code in here, but will shortly also write up some more formal documentation.
The text was updated successfully, but these errors were encountered: