怎么在iOS中利用UICollectionView实现横向滑动

  介绍

这期内容当中小编将会给大家带来有关怎么在iOS中利用UICollectionView实现横向滑动,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

UICollectionView的横向滚动

////SCVisitorInputAccessoryView.m//,访客通行录入页面——访客姓名输入历史的InputAccessory      # import “SCInputAccessoryView.h"   # import “SCInputAccessoryCell.h"      # define  SCHorizontalMargin  15.0 f   # define  SCVerticalMargin  10.0 f      @interface  SCInputAccessoryView  (), & lt; UICollectionViewDelegate,, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>      @property (弱,,原子),IBOutlet  UICollectionView  * collectionView;///,名字记录的数组   @property (原子,,强烈),NSMutableArray  * nameArray;      @end         @implementation  SCInputAccessoryView      +,(instancetype) loadNibView  {   ,return  [[[NSBundle  mainBundle], loadNibNamed: [SCInputAccessoryView 名称],老板:self 选择:nil),, objectAtIndex: 0];   }      安康;(空白)awakeFromNib  {   ,[super  awakeFromNib];=,self.clipsToBounds 是的;=,self.collectionView.delegate 自我;=,self.collectionView.dataSource 自我;   ,[self  setupView];   }      安康;(空白)setupView  {      ,///设置此属性为yes 不满一屏幕,也能滚动=,self.collectionView.alwaysBounceHorizontal 是的;=,self.collectionView.showsHorizontalScrollIndicator 没有;   ,//1。创建流水布的局   ,UICollectionViewFlowLayout  * layout =, [[UICollectionViewFlowLayout  alloc], init);=,,layout.scrollDirection  UICollectionViewScrollDirectionHorizontal;=,self.collectionView.collectionViewLayout 布局;   ,[self  registerNibWithTableView];   }      # pragma  mark 安康;代理方法,Delegate 方法//,设置分区      安康;(NSInteger) numberOfSectionsInCollectionView:(UICollectionView  *) collectionView  {   ,return  1;   }//,每个分区上得元素个数   安康;(NSInteger) collectionView:(UICollectionView  *) collectionView  numberOfItemsInSection: (NSInteger) section  {   ,return  self.nameArray.count;   }//,设置细胞   安康;(UICollectionViewCell  *) collectionView:(UICollectionView  *) collectionView  cellForItemAtIndexPath: (NSIndexPath  *) indexPath  {      ,SCInputAccessoryCell  * cell =, (collectionView  dequeueReusableCellWithReuseIdentifier: NSStringFromClass ([SCInputAccessoryCell 类]),forIndexPath: indexPath);   ,(cell  refreshCellWithTitle: self.nameArray [indexpath。row]];   ,return 细胞;   }//,设置细胞大小,itemSize:可以给每一个细胞指定不同的尺寸   安康;(CGSize) collectionView:(UICollectionView  *) collectionView 布局:(UICollectionViewLayout *) collectionViewLayout  sizeForItemAtIndexPath: (NSIndexPath  *) indexPath  {   ,CGFloat  height =, 35.0 f;   ,CGFloat  width =, [self  gainStringWidthWithString: self.nameArray (indexpath。row),字体:15.0 f 高度:高度);   ,return  CGSizeMake(宽度,高度);   }//,设置UIcollectionView整体的内边距(这样物品不贴边显示)   安康;(UIEdgeInsets) collectionView:(UICollectionView  *) collectionView 布局:(UICollectionViewLayout  *) collectionViewLayout  insetForSectionAtIndex: (NSInteger) section  {   ,//上,左,下,右   ,return  UIEdgeInsetsMake (SCHorizontalMargin, SCVerticalMargin,还以为,SCVerticalMargin, SCHorizontalMargin);   }//,设置minimumLineSpacing:细胞上下之间最小的距离   安康;(CGFloat) collectionView:(UICollectionView  *) collectionView 布局:(UICollectionViewLayout  *) collectionViewLayout  minimumLineSpacingForSectionAtIndex: (NSInteger) section  {   ,return  SCHorizontalMargin;   }//,设置minimumInteritemSpacing:细胞左右之间最小的距离   安康;(CGFloat) collectionView:(UICollectionView  *) collectionView 布局:(UICollectionViewLayout  *) collectionViewLayout  minimumInteritemSpacingForSectionAtIndex: (NSInteger) section  {   ,return  SCHorizontalMargin;   }//,选中细胞的回调   安康;(空白)collectionView:(UICollectionView  *) collectionView  didSelectItemAtIndexPath: (NSIndexPath  *) indexPath  {   ,if  (self.selectRowBlock), {   ,self.selectRowBlock (indexpath。row, self.nameArray [indexpath。row]);   ,}   }      # pragma  mark 作用;对外方法,Public 方法///,数组数组里面放的元素,必须字符串类型的   安康;(空白)refreshUIWithNameArray:(NSArray

怎么在iOS中利用UICollectionView实现横向滑动