zoukankan      html  css  js  c++  java
  • 不规则分页,如图

    UICollectionViewFlowLayout 来做

    PagingEnableLayout.h

    #import <UIKit/UIKit.h>
    
    @interface PagingEnableLayout : UICollectionViewFlowLayout
    
    @end
    

    PagingEnableLayout.m

    #import "PagingEnableLayout.h"
    #import <objc/message.h>
    
    #define ScreenWidth [UIScreen mainScreen].bounds.size.width
    
    @implementation PagingEnableLayout
    
    - (void)prepareLayout{
        [super prepareLayout];
        
        
        //屏幕宽去掉中间的cell宽度的大小
        CGFloat contentInset = 40; 
        self.collectionView.decelerationRate = UIScrollViewDecelerationRateFast;
        self.collectionView.contentInset = UIEdgeInsetsMake(0, contentInset*0.5, 0, contentInset*0.5);//整个collectionView
        //interpageSpacing
        if ([self.collectionView respondsToSelector:NSSelectorFromString(@"_setInterpageSpacing:")]) {
            ((void(*)(id,SEL,CGSize))objc_msgSend)(self.collectionView,NSSelectorFromString(@"_setInterpageSpacing:"),CGSizeMake(-(contentInset-self.minimumInteritemSpacing), 0));//minimumInteritemSpacing 在xib中设置的 cell之间的间隔
        }
        if ([self.collectionView respondsToSelector:NSSelectorFromString(@"_setPagingOrigin:")]) {
            ((void(*)(id,SEL,CGPoint))objc_msgSend)(self.collectionView,NSSelectorFromString(@"_setPagingOrigin:"),CGPointMake(-contentInset*0.5, 0)); //让下一页延伸到上一页 l
        }
    }
    
    @end
    

    使用时,设置

    UICollectionViewCell的大小

    - ( CGSize )collectionView:( UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:( NSIndexPath *)indexPath {
      
        return CGSizeMake(([UIScreen mainScreen].bounds.size.width-40), 340);
        
    }
    

    中间的空白间隙就是这里设置的。

    参考自https://github.com/abcdezg/PagingEnableLayout

    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    jquery.validate.js【简单实用的表单验证框架】
    velocity.js实现页面滚动切换效果
    站在巨人的肩膀上——制作酷炫web幻灯片
    简单说说随机打乱数组的方法
    JS数据结构之BinarySearchTree
    做一个extjs的扩展
    【OneAPM】极客编程挑战#025:发挥想象生成漂亮炫酷的SVG动画效果
    将博客搬至CSDN
    练习作品7:批量做字库 识别码
    联系作品6 模版打印 奖状
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/12786265.html
Copyright © 2011-2022 走看看