通過在UICollectionView和UIViewController實現多行多列單元格效果

jopen 10年前發布 | 51K 次閱讀 Voltron iOS開發 移動開發

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.baiduhome.net/lib/view/home/1414740299356

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!