iPhone 7/8 plus、iPhone 7/8s & 上的 CollectionView 问题iPhone X [英] CollectionView Issue on iPhone 7/8 plus, iPhone 7/8s & iPhone X

查看:38
本文介绍了iPhone 7/8 plus、iPhone 7/8s & 上的 CollectionView 问题iPhone X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个简单的问题,但我不知道如何摆脱它.

This is probably a simple issue but, I don't know how to get rid of it.

我的问题:

  • 当我在 iPhone 8 Plus 上运行时,我的 CollectionView 正是我期望(见 Image1).
  • 当我在 iPhone X 上运行时,我的 CollectionView具有不同的布局(参见 Image2).

我想要什么:

使用 UICollectionView,我想在每部 iPhone 上获得类似 Image1 的布局.

Using a UICollectionView, I would like to get a layout like Image1, on every single iPhone.

你能给我一些解决这个问题的技巧吗?

Could you pls give me some tips to solve this issue ?

图像 1(预期结果):

iPhone 8 Plus 上的结果

Result on the iPhone 8 Plus

Image2(错误结果):

iPhone X 上的结果

Result on the iPhone X

推荐答案

使用以下 Delegate 方法:UICollectionViewDelegateFlowLayout

Use following Delegate method: UICollectionViewDelegateFlowLayout

    func collectionView(_ collectionView: UICollectionView,
                    layout collectionViewLayout: UICollectionViewLayout,
                    sizeForItemAt indexPath: IndexPath) -> CGSize {

          return CGSize(width: (self.view.frame.width - 8) / 3.0 , height: (self.view.frame.width - 8) / 3.0)
     }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {

        return UIEdgeInsetsMake(8, 8, 0, 8)
    }

这篇关于iPhone 7/8 plus、iPhone 7/8s & 上的 CollectionView 问题iPhone X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆