【问题标题】:How to expand collectionview cell to full screen [closed]如何将collectionview单元格扩展到全屏[关闭]
【发布时间】:2016-10-31 16:13:29
【问题描述】:

我正在尝试全屏打印图像 我使用了 UICollectionViewDelegateFlowLayout 这是我的代码

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let itemWidth = collectionView.bounds.width
        let itemHeight = collectionView.bounds.height
        return CGSize(width: itemWidth, height: itemHeight)
    }

但它不会全屏显示内容,它会从顶部和底部腾出空间

【问题讨论】:

  • 尝试启用页面
  • 我想将单元格扩展到全屏,据我所知,启用的页面将为我提供布局导航。但我想将 uicollectionview 单元格扩展到全屏
  • 每个单元格还是特定单元格?

标签: ios objective-c uicollectionview uicollectionviewcell uicollectionviewlayout


【解决方案1】:

如果您想增加单元格大小以适应您的屏幕,您可以使用此方法。

目标-C

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
}

斯威夫特

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        //For entire screen size
        let screenSize = UIScreen.main.bounds.size
        return screenSize
        //If you want to fit the size with the size of ViewController use bellow
        let viewControllerSize = self.view.frame.size
        return viewControllerSize

        // Even you can set the cell to uicollectionview size
        let cvRect = collectionView.frame
        return CGSize(width: cvRect.width, height: cvRect.height)


    }

【讨论】:

  • 我现在可以做到了。在collectionview单元格中呈现视图是合理的还是正确的方式?有没有更好的方法来做到这一点。
  • 一定要在storyboard中设置collection view的Estimate Size为None,否则即使调用了上面的sizeForItemAt方法,大小也不会改变。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多