最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ios的collection控件的自定義布局實現(xiàn)與設(shè)計

 更新時間:2017年12月08日 10:37:20   作者:技術(shù)小百科  
這篇文章主要介紹了mac、iOS端支持自定義布局的collection控件的實現(xiàn)與設(shè)計,需要的朋友學(xué)習(xí)參考下吧。

collection控件用來實現(xiàn)界面的各種自定義布局,最常用其作為橫向、豎向的布局控件。很早之前,系統(tǒng)對于collection的支持并不是很好。所以自己實現(xiàn)了支持自定義布局、自定義cell的collection控件。自定義的collection可以滿足所有的產(chǎn)品特殊需求及動態(tài)效果,例如在某些特殊情況下可能需要除選中cell之外的其它cell執(zhí)行布局動畫等。在collection的基礎(chǔ)之上,我又實現(xiàn)了支持cell拖動、拖離窗體的tabview控件。本文主要介紹自定義collection的設(shè)計與實現(xiàn),后續(xù)持續(xù)更新多tab的tabview控件。

我有幾張阿里云幸運券分享給你,用券購買或者升級阿里云相應(yīng)產(chǎn)品會有特惠驚喜哦!把想要買的產(chǎn)品的幸運券都領(lǐng)走吧!快下手,馬上就要搶光了。

產(chǎn)品中的一些實現(xiàn)效果

mac旺旺表情面板,實現(xiàn)grid與橫向布局

mac千牛工作臺用作橫向布局

iOS千牛歷史登錄頁面實現(xiàn)當(dāng)前選中cell變大并且選中cell總中最中位置校準動效的效果

collection

collection主要包括:繼承scrollview的collectionView,數(shù)據(jù)源協(xié)議collectionViewDataSource,事件響應(yīng)協(xié)議collectoinViewDelegate,布局基類collectoinLayout以及展示單元collectionCellView。

模塊圖如下:

 collectionView

collection容器包含指實現(xiàn)collectionViewDataSource、collectoinViewDelegate協(xié)議的指針以及collectoinLayout成員,同時維護collectoinCellView的控件重用。

@interface WWCollectionView : NSScrollView
// 布局對象
@property (retain) WWCollectionViewLayout *layout;
// 數(shù)據(jù)源
@property (weak) id dataSource;
// 事件響應(yīng)
@property (weak) id delegate;
// 重加載數(shù)據(jù)
(void)reloadData;
// 重排布
(void)invalidateLayout;
// 取消返回選中
(void)unSelectedAll;
// 注冊重用對象
(void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;
// 對象重用
(id)dequeueReusableCellWithReuseIdentifier:(NSString )identifier forIndexPath:(NSIndexPath )indexPath;
// 設(shè)置選中對象
(void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;
// 當(dāng)前選中對象
(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

collectionViewDataSource

collection展示的數(shù)據(jù)源,由宿主實現(xiàn)。

@protocol WWCollectionViewDataSource 
// 返回indexPath下標(biāo)的cell
(WWCollectionCellView )collectView:(WWCollectionView )collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
// 總cell個數(shù)
(NSInteger)numberOfItemInCollectionView:(WWCollectionView *)collectionView;
// cell的數(shù)據(jù)
(id)collectionView:(WWCollectionView )colletionView objectValueAtIndexPath:(NSIndexPath )indexPath;
@end

collectoinViewDelegate

collection事件的回調(diào)響應(yīng),由宿主實現(xiàn)。

@protocol WWCollectionViewDelegate 
// indexPath元素被選中
(void)collectionView:(WWCollectionView )collectionView didSelectItemAtIndexPath:(NSIndexPath )indexPath;
// 是否支持選中
(BOOL)collectionView:(WWCollectionView )collectionView shouldSelectItemsAtIndexPaths:(NSIndexPath )indexPath;
@end

collectoinLayout

collectionCellView的布局方案。

@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

collectoinCellView

collection展示的cell控件。

@interface WWCollectionCellView : NSView
// 當(dāng)前cell被選中
@property (nonatomic, assign) BOOL selected;
// 數(shù)據(jù)
@property (nonatomic, retain) id dataValue;
// 使用前重置展示效果
(void)reset;
@end

相關(guān)文章

  • iOS實現(xiàn)選項卡效果的方法

    iOS實現(xiàn)選項卡效果的方法

    選項卡在我們?nèi)粘i_發(fā)的時候經(jīng)常要用到,所以這篇文章給大家分享一種iOS實現(xiàn)的簡單選項卡效果,很適合大家學(xué)習(xí)和使用,有需要的可以參考借鑒,下面來一起看看吧。
    2016-09-09
  • IOS開發(fā) UIAlertController詳解及實例代碼

    IOS開發(fā) UIAlertController詳解及實例代碼

    這篇文章主要介紹了 IOS開發(fā) UIAlertController詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • iOS利用CoreImage實現(xiàn)人臉識別詳解

    iOS利用CoreImage實現(xiàn)人臉識別詳解

    OS的人臉識別從iOS 5(2011)就有了,不過一直沒怎么被關(guān)注過。人臉識別API允許開發(fā)者不僅可以檢測人臉,也可以檢測到面部的一些特殊屬性,比如說微笑或眨眼。下面這篇文章主要給大家介紹了iOS利用CoreImage實現(xiàn)人臉識別的相關(guān)資料,需要的朋友可以參考下。
    2017-05-05
  • IOS 開發(fā)之PickerView自定義視圖的實例詳解

    IOS 開發(fā)之PickerView自定義視圖的實例詳解

    這篇文章主要介紹了IOS 開發(fā)之PickerView自定義視圖的實例詳解的相關(guān)資料,這里提供實例幫助大家學(xué)習(xí)理解這部分知識,需要的朋友可以參考下
    2017-08-08
  • iOS輸入框的字數(shù)統(tǒng)計/最大長度限制詳解

    iOS輸入框的字數(shù)統(tǒng)計/最大長度限制詳解

    在開發(fā)中經(jīng)常會遇到鍵盤輸入的字符長度的限制,下面這篇文章主要給大家介紹了關(guān)于iOS輸入框的字數(shù)統(tǒng)計/最大長度限制的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-06-06
  • iOS自定義button抖動效果并實現(xiàn)右上角刪除按鈕

    iOS自定義button抖動效果并實現(xiàn)右上角刪除按鈕

    這篇文章主要為大家詳細介紹了iOS自定義button抖動效果并實現(xiàn)右上角刪除按鈕的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • iOS中常見的視圖和圖片處理示例詳解

    iOS中常見的視圖和圖片處理示例詳解

    在日常ios開發(fā)中經(jīng)常會遇到視圖和圖片的處理,下面這篇文章主要給大家總結(jié)介紹了關(guān)于iOS中常見的視圖和圖片處理的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)和工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下。
    2017-10-10
  • iOS開發(fā)實現(xiàn)計算器功能

    iOS開發(fā)實現(xiàn)計算器功能

    這篇文章主要為大家詳細介紹了iOS開發(fā)實現(xiàn)計算器功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • iOS 按鈕上的文字添加下劃線的方法

    iOS 按鈕上的文字添加下劃線的方法

    這篇文章主要介紹了iOS 按鈕上的文字添加下劃線的方法的相關(guān)資料,需要的朋友可以參考下
    2016-05-05
  • iOS UIButton擴大按鈕響應(yīng)區(qū)域的解決方法

    iOS UIButton擴大按鈕響應(yīng)區(qū)域的解決方法

    這篇文章主要為大家詳細介紹了iOS UIButton擴大按鈕響應(yīng)區(qū)域的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-08-08

最新評論

昆山市| 慈利县| 静海县| 新邵县| 布拖县| 兴城市| 垣曲县| 治县。| 广元市| 罗城| 土默特左旗| 灵山县| 昌江| 本溪市| 泽普县| 鄂尔多斯市| 舒城县| 临朐县| 榆树市| 广德县| 二连浩特市| 阿瓦提县| 博白县| 惠安县| 筠连县| 烟台市| 白朗县| 固安县| 南汇区| 会宁县| 苍梧县| 旺苍县| 富裕县| 东港市| 南安市| 乌兰察布市| 常熟市| 东宁县| 湘乡市| 牟定县| 江阴市|