【发布时间】:2018-01-05 23:33:33
【问题描述】:
我正在制作一个包含两个主要视图的天气。 第一个是主视图,它有一个可滚动的 UICollectionView,其中有代表小型天气卡的单元格。第二个是不同的视图,其中显示了更详细的所有天气细节。
我想在集合视图之上创建一个 UIView 并将其扩大以填满屏幕。可悲的是,我一直失败,找不到合适的方法来做到这一点。 当单元格被按下时,我想在单元格顶部创建一个 UIView(获取它在视图上的位置),然后将其增长以填充屏幕。
我打算把代码放在哪里:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Cell [\(indexPath.row)] selected.")
// Get cell position on screen:
let attributes = collectionView.layoutAttributesForItem(at: indexPath)
let cellRect = attributes?.frame
let frameCellInSuperview = collectionView.convert(cellRect!, to: collectionView.superview)
print("x: \(Double(frameCellInSuperview.origin.x)), y: \(Double(frameCellInSuperview.origin.y))")
// Create a small UIView in the exact same position
// Grow the UIView to fill the screen
}
【问题讨论】:
标签: ios iphone uiview swift3 uicollectionview