通过在UICollectionView和UIViewController实现多行多列单元格效果
jopen
10年前
Voltron通过在UICollectionView和UIViewController实现多行多列单元格效果。既可以接收单个单元格手势事件,也可以接受一组单元格的手势事件。
UICollectionView
with UIViewController
s instead of cells.
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 ofUICollectionView
andWMLCollectionViewCell
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]; }