通过在UICollectionView和UIViewController实现多行多列单元格效果

分享到:

Voltron通过在UICollectionView和UIViewController实现多行多列单元格效果。既可以接收单个单元格手势事件,也可以接受一组单元格的手势事件。

通过在UICollectionView和UIViewController实现多行多列单元格效果

UICollectionView with UIViewControllers instead of cells.

Illustration

View controller containment compliant!

Installation

Voltron is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Voltron", '~> x.x.x'

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

  • #import <Voltron/Voltron.h>

  • Use WMLCollectionView instead of UICollectionView and WMLCollectionViewCell for cells, displaying view controllers.

  • Set the collectionView.containerViewController to the view controller that is hosting children view controllers.

  • Implement a data source method:

- (UIViewController *)collectionView:(WMLCollectionView *)collectionView controllerForIdentifier:(NSString *)identifier {
if ([identifier isEqualToString:@"Login"]) {
return [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
} else if ([identifier isEqualToString:@"Profile"]) {
return [self.storyboard instantiateViewControllerWithIdentifier:@"UserProfileViewController"];
}
}
  • Once done displaying cell, call didEndDisplayingCell: passing the cell to give the collection view a clue that it can be recycled.
- (void)collectionView:(WMLCollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView didEndDisplayingCell:cell];
}

项目主页:http://www.open-open.com/lib/view/home/1414740299356

昵    称:
验证码:

相关文档: