@interface WWCollectionView : NSScrollView // 布局对象 @property (retain) WWCollectionViewLayout *layout; // 数据源 @property (weak) id dataSource; // 事件响应 @property (weak) id delegate; // 重加载数据 (void)reloadData; // 重排布 (void)invalidateLayout; // 取消返回选中 (void)unSelectedAll; // 注册重用对象 (void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier; // 对象重用 (id)dequeueReusableCellWithReuseIdentifier:(NSString )identifier forIndexPath:(NSIndexPath )indexPath; // 设置选中对象 (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated; // 当前选中对象 (NSIndexPath *)selectedItem; // 重加载indexPath item (void)reloadItemsAtIndexPath:(NSIndexPath *)indexPath; // 插入 (void)insertItemsAtIndexPath:(NSIndexPath *)indexPath withAnimate:(BOOL)animate; // 删除 (void)deleteItemsAtIndexPath:(NSIndexPath *)indexPath withAnimate:(BOOL)animate; // 重新排列 (void)relayoutWithAnimation:(BOOL)animated completion:(void (^)(BOOL finished))completion; // 滚动到aPoint (void)scrollToPoint:(NSPoint)aPoint withAnimate:(BOOL)animate; @end
@protocol WWCollectionViewDataSource // 返回indexPath下标的cell (WWCollectionCellView )collectView:(WWCollectionView )collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath; // 总cell个数 (NSInteger)numberOfItemInCollectionView:(WWCollectionView *)collectionView; // cell的数据 (id)collectionView:(WWCollectionView )colletionView objectValueAtIndexPath:(NSIndexPath )indexPath; @end
@protocol WWCollectionViewDelegate // indexPath元素被选中 (void)collectionView:(WWCollectionView )collectionView didSelectItemAtIndexPath:(NSIndexPath )indexPath; // 是否支持选中 (BOOL)collectionView:(WWCollectionView )collectionView shouldSelectItemsAtIndexPaths:(NSIndexPath )indexPath; @end
@interface WWCollectionViewLayout : NSObject // 布局基类 @property (weak) WWCollectionView *collectionView; // 每个cell元素大小 @property (assign) NSSize itemSize; // edgeInsets @property (assign) NSEdgeInsets edgeInsets; // scrollview使用,表示整个画布大小 @property (assign) NSSize viewContentSize; (instancetype)initWithCollectionView:(WWCollectionView *)collectionView; (void)invalidateLayout; // 返回index的cell大小 (NSRect)frameForIndexPath:(NSIndexPath *)index total:(NSInteger)total; (NSSize)collectionViewContentSize; @end // 横向布局控件 @interface WWFlowCollectionViewLayout : WWCollectionViewLayout @property (assign) CGFloat headMargin; @property (assign) CGFloat tailMargin; @end // grid布局控件 @interface WWGridCollectionViewLayout : WWCollectionViewLayout // 每行多少个 @property (assign) NSInteger numberPerRow; @property (assign) CGFloat headMargin; @property (assign) CGFloat tailMargin; @end
@implementation WWFlowCollectionViewLayout
(void)invalidateLayout {
NSInteger cellCount = [self.collectionView.dataSource numberOfItemInCollectionView:self.collectionView];
CGRect bounds = self.collectionView.bounds;
// 画布宽度
CGFloat width = _headMargin + _tailMargin + (cellCount - 1) (self.edgeInsets.left + self.edgeInsets.right) + self.itemSize.width cellCount;
if (width < bounds.size.width) {
width = bounds.size.width;
}
self.viewContentSize = NSMakeSize(width, bounds.size.height);
[super invalidateLayout];
}
(NSRect)frameForIndexPath:(NSIndexPath *)index total:(NSInteger)total {
CGFloat leftPos = self.headMargin + [index indexAtPosition:0] * (self.itemSize.width + self.edgeInsets.left + self.edgeInsets.right);
// 返回cell的rect
return NSMakeRect(leftPos, self.edgeInsets.top, self.itemSize.width, self.itemSize.height);
}
@end
@interface WWCollectionCellView : NSView // 当前cell被选中 @property (nonatomic, assign) BOOL selected; // 数据 @property (nonatomic, retain) id dataValue; // 使用前重置展示效果 (void)reset; @end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有