欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

怎么在iOS中使用UICollectionView實(shí)現(xiàn)列表頭部拉伸效果-創(chuàng)新互聯(lián)

本篇文章為大家展示了怎么在iOS中使用UICollectionView實(shí)現(xiàn)列表頭部拉伸效果,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

成都創(chuàng)新互聯(lián)公司是一家朝氣蓬勃的網(wǎng)站建設(shè)公司。公司專(zhuān)注于為企業(yè)提供信息化建設(shè)解決方案。從事網(wǎng)站開(kāi)發(fā),網(wǎng)站制作,網(wǎng)站設(shè)計(jì),網(wǎng)站模板,微信公眾號(hào)開(kāi)發(fā),軟件開(kāi)發(fā),小程序制作,10余年建站對(duì)戶外休閑椅等多個(gè)領(lǐng)域,擁有豐富的網(wǎng)站制作經(jīng)驗(yàn)。

OC版本

創(chuàng)建一個(gè)類(lèi) CustomCollectionViewFlowLayout 繼承 UICollectionViewFlowLayout

#import "CustomCollectionViewFlowLayout.h"

@implementation CustomCollectionViewFlowLayout

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
  return YES;
}

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {

  UICollectionView *collectionView = [self collectionView];
  UIEdgeInsets insets = [collectionView contentInset];
  CGPoint offset = [collectionView contentOffset];
  CGFloat minY = -insets.top;

  NSArray *attributes = [super layoutAttributesForElementsInRect:rect];

  if (offset.y < minY) {

    CGSize headerSize = [self headerReferenceSize];
    CGFloat deltaY = fabsf(offset.y - minY);

    for (UICollectionViewLayoutAttributes *attrs in attributes) {

      if ([attrs representedElementKind] == UICollectionElementKindSectionHeader) {

        CGRect headerRect = [attrs frame];
        headerRect.size.height = MAX(minY, headerSize.height + deltaY);
        headerRect.origin.y = headerRect.origin.y - deltaY;
        [attrs setFrame:headerRect];
        break;
      }
    }
  }

  return attributes;
}

@end

在控制器中使用 先導(dǎo)入頭文件

// 創(chuàng)建collectionView
  CustomCollectionViewFlowLayout *flowLayout=[[CustomCollectionViewFlowLayout alloc] init];
  [flowLayout setSectionInset:UIEdgeInsetsMake(0, 0, 10, 0)];
  [flowLayout setItemSize:CGSizeMake(kScreenWidth / collectionCellW, kScreenWidth / collectionCellW)];
  [flowLayout setHeaderReferenceSize:CGSizeMake(kScreenWidth, userInfoImageViewH)];
  [flowLayout setFooterReferenceSize:CGSizeMake(kScreenWidth, 83)];
  [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
  [flowLayout setMinimumInteritemSpacing:0.0];
  [flowLayout setMinimumLineSpacing:0.0];

  self.homeCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 44)collectionViewLayout:flowLayout];
  self.homeCollectionView.backgroundColor = kViewBackgroundColor;
  self.homeCollectionView.alwaysBounceVertical = YES;
  self.homeCollectionView.showsVerticalScrollIndicator = NO;
  //設(shè)置代理
  self.homeCollectionView.delegate = self;
  self.homeCollectionView.dataSource = self;
  [self.view addSubview:self.homeCollectionView];

  // 注冊(cè)表頭
  [self.homeCollectionView registerClass:[YJHeaderCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionHeaderView];

  // 注冊(cè)表尾
  [self.homeCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:kCollectionFooterView];

Swift版

喜歡swift 不需要導(dǎo)入頭文件那么麻煩

//
// CustomCollectionViewFlowLayout.swift
// 
//
// Created by GongHui_YJ on 16/8/4.
// Copyright &copy; 2016年YangJian. All rights reserved.
//

import UIKit

class CustomCollectionViewFlowLayout: UICollectionViewFlowLayout {

  override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
    return true
  }

  override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
    let collectionView = self.collectionView
    let insets = collectionView?.contentInset
    let offset = collectionView?.contentOffset
    let minY = -((insets?.top)!)

    let attributesArray = super.layoutAttributesForElementsInRect(rect)
    if offset!.y < minY {
      let headerSize = self.headerReferenceSize
      let deltaY = CGFloat(fabsf(Float((offset?.y)! - CGFloat(minY))))

      for attrs:UICollectionViewLayoutAttributes in attributesArray! {

        if attrs.representedElementKind == UICollectionElementKindSectionHeader {
          var headerRect = attrs.frame
          headerRect.size.height = max(minY, headerSize.height + deltaY)
          headerRect.origin.y = headerRect.origin.y - deltaY
          attrs.frame = headerRect
          break
        }
      }
    }

    return attributesArray
  }

}

在控制器 viewDidLoad方法實(shí)現(xiàn)

let customFlowLayout = CustomCollectionViewFlowLayout()
  customFlowLayout.headerReferenceSize = CGSizeMake(kScreenWidth, 203)
  customFlowLayout.footerReferenceSize = CGSizeMake(kScreenWidth, 83)
  customFlowLayout.minimumInteritemSpacing = 0
  customFlowLayout.minimumLineSpacing = 0
  customFlowLayout.itemSize = CGSizeMake(kScreenWidth / 3.000006, kScreenWidth / 3.00006)
  customFlowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 10, 0)

  self.homeCollectionView.setCollectionViewLayout(customFlowLayout, animated: true)
  self.homeCollectionView.backgroundColor = kViewBackgroundColor
  self.homeCollectionView.alwaysBounceVertical = true
  let nib = UINib(nibName: "CommonCollectionViewCell", bundle: nil)
  self.homeCollectionView.registerNib(nib, forCellWithReuseIdentifier: cellId)

  // 注冊(cè)表頭表尾
  let headerNib = UINib(nibName: "HeaderCollectionReusableView", bundle: nil)
  self.homeCollectionView.registerNib(headerNib, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: collectionHeaderId)

  self.homeCollectionView.registerClass(UICollectionReusableView.classForCoder(), forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: collectionFooterId)

上述內(nèi)容就是怎么在iOS中使用UICollectionView實(shí)現(xiàn)列表頭部拉伸效果,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站chinadenli.net,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

本文標(biāo)題:怎么在iOS中使用UICollectionView實(shí)現(xiàn)列表頭部拉伸效果-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://chinadenli.net/article36/ejhsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、靜態(tài)網(wǎng)站虛擬主機(jī)、網(wǎng)站設(shè)計(jì)、品牌網(wǎng)站制作定制開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)
免费观看潮喷到高潮大叫| 亚洲三级视频在线观看免费| 国产精品免费视频久久| 在线观看欧美视频一区| 国产精品一区二区高潮| 欧美日韩国产的另类视频| 日本不卡视频在线观看| 99久久精品午夜一区二| 久久精品国产在热久久| 日韩欧美好看的剧情片免费| 国产在线小视频你懂的| 色综合伊人天天综合网中文| 国产精品久久久久久久久久久痴汉| 成人午夜激情在线免费观看 | 国产精品一区二区三区日韩av| 日韩精品视频香蕉视频| 欧美日韩国产亚洲三级理论片| 日本中文字幕在线精品| 中文精品人妻一区二区| 国产中文另类天堂二区| 91日韩欧美国产视频| 中文日韩精品视频在线| 精品国模一区二区三区欧美| 千仞雪下面好爽好紧好湿全文| 亚洲精品熟女国产多毛| 日韩中文字幕人妻精品| 台湾综合熟女一区二区| 日本在线 一区 二区| 免费观看日韩一级黄色大片| 欧美日韩亚洲巨色人妻| 日韩三极片在线免费播放| 精品久久少妇激情视频| 激情内射日本一区二区三区| 激情五月激情婷婷丁香| 亚洲一区二区精品免费视频| 国产美女精品人人做人人爽| 午夜精品成年人免费视频| 高清国产日韩欧美熟女| 欧美精品亚洲精品日韩精品| 狠狠做深爱婷婷久久综合| 午夜精品国产一区在线观看|