Android就像在iOS上有标签的查看分页器一样

vin*_*n25 8 uitabbar ios uicollectionview

我想知道什么是最好的方法来实现像iOS一样的视图分页器与iOS上的标签,如在FIFA世界杯应用程序上找到的 参考图像

我能想到的各种方法是:

  1. 定制的UITabBarController带有滑动和平移手势 - 我试过这个,滑动体验不如FIFA应用程序那么流畅.它像新的Skype应用程序一样迟缓(想想他们正在使用这种方法).
  2. 页面视图控制器 - 我也试过这个,但遇到了一些奇怪的问题.之后没有尝试过多.
  3. 具有水平分页的集合视图控制器 - 这对我来说似乎是最好的方法,但我不确定内存管理.

我目前的实现 - 截至目前我有三个标签栏条目.我为每个人都有单独的视图控制器.这是我使用水平分页集合视图实现它的方式:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

NSInteger indexNumber = indexPath.row;
UICollectionViewCell *cell;

switch (indexNumber) {
    case 0:
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell1" forIndexPath:indexPath];
        [cell.contentView addSubview:self.firstViewControllerObject.view];
        break;
    case 1:
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell2" forIndexPath:indexPath];
        [cell.contentView addSubview:self.secondViewControllerObject.view];
        break;
    case 2:
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell3" forIndexPath:indexPath];
        [cell.contentView addSubview:self.thirdViewControllerObject.view];
        break;

    default:
        break;
}

return cell;
}
Run Code Online (Sandbox Code Playgroud)

我无法找到更好地管理细胞的方法,因此我制作了不同的实体.如何使用这种方法做得更好,或者如果这种方法不好,我应该使用什么?

小智 4

实际上对于iOS来说,实现像分段控制这样的原生组件将是一个更好的方法,而不是尝试像原生android所提供的那样来实现。

但如果你真的想尝试像 android 这样的 viewpager,我想你可以尝试在这里使用这个库。我尝试自己实现它,看起来很棒。希望能帮助到你。