gpt4 book ai didi

ios - 在所有屏幕尺寸的 CollectionView 中正确显示 Instagram 照片

转载 作者:行者123 更新时间:2023-11-28 13:16:50 28 4
gpt4 key购买 nike

这个让我很困惑。好的,我们开始吧。我正在拉下 IG 图片,它们有 3 种尺寸:150x150、306x306、640x640

我想做的是在所有 iPhone 屏幕尺寸(5、5S、6、6+)上显示它们 3。 306x306 的尺寸缩小速度非常快,而且看起来很棒。这就是我的起点(150x150 有点模糊,640x640 也是一个选项,我也可以使用它们,只是想节省一些带宽)。

边缘可以与两侧齐平,它们之间有 1 px/pt 线。我为此绞尽脑汁。我的理解是(下面的)函数应该覆盖我的 Storyboard 中的任何其他设置,以及我应该关注的地方(我已经打印出我从 println() 捕获的尺寸。

我的挑战是找出在所有屏幕上工作所需的最终宽度和高度。我已经尝试了很多排列,但还没有确定。我很接近,但没有雪茄。这都是在 Storyboard中使用 CollectionView。建议表示赞赏。这是个大问题,整天都在这个问题上度过。

我认为自动布局根本没有帮助,这一切都必须在代码中完成,但谁知道呢?

谢谢[很多!] :-)

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

var width = CGRectGetWidth(collectionView.bounds)

println("width: \(width)")

// iphone5 320
// iphone5S 320
// iphone6 375
// iphone 6+ 414

return CGSize(width: NeedCorrectWidthHere, height: NeedCorrectHeightHere)

}

这确实部分有效,图像之间有间隙:

var screenWidth = CGRectGetWidth(collectionView.bounds)
var cellWidth = screenWidth/3

return CGSize(width: cellWidth-10, height: cellWidth-10)

最佳答案

这似乎奏效了。最后一个非常简单的解决方案。

   func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

var screenWidth = CGRectGetWidth(collectionView.bounds)
var cellWidth = screenWidth/3

return CGSize(width: cellWidth-2, height: cellWidth-2)

}

func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 3
}

func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 3
}

关于ios - 在所有屏幕尺寸的 CollectionView 中正确显示 Instagram 照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28687464/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com