无法将类型 'CGPoint' 的值分配给类型 'CGFloat'
Cannot assign value of type 'CGPoint' to type 'CGFloat'
首先,我试图获取布局并计算单元格的宽度,包括 spacing.After,我正在尝试计算当前显示 Item.The 最终结果的索引,我想要scrollview 在我停止滚动时计数并结束吸毒但它给我一个计算错误。 "Cannot assign value of type 'CGPoint' to type 'CGFloat'" 不知道如何解决这个问题。需要帮助
这是函数代码
extension HomeViewController : UIScrollViewDelegate {
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint,targetContentOffset targetContentOffSet: UnsafeMutablePointer<CGPoint>) {
let layOut = self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout
let cellWidthIncludingSpacing = layOut.itemSize.width + layOut.minimumLineSpacing
var offSet = targetContentOffSet.pointee.x
let index = (offSet.x + scrollView.contentInset.left) / cellWidthIncludingSpacing //error Value of type 'CGFloat' has no member 'x'
let roundedIndex = round(visibleWidth)
offSet = CGPoint(x: roundedIndex * cellWidthIncludingSpacing - scrollView.contentInset.left,y: -scrollView.contentInset.top) //"Cannot assign value of type 'CGPoint' to type 'CGFloat'"
targetContentOffSet.pointee = offSet
}
}
看看你的这行代码:
var offSet = targetContentOffSet.pointee.x
Swift 为 offSet
推导出什么类型?可以在Xcode中option-click它来查找,但我们可以看到它必须是CGPoint.x
的类型,即CGFloat
.
从你函数的其余行来看,我猜你希望它的类型为 CGPoint
,因此将其更改为:
var offSet = targetContentOffset.pointee
首先,我试图获取布局并计算单元格的宽度,包括 spacing.After,我正在尝试计算当前显示 Item.The 最终结果的索引,我想要scrollview 在我停止滚动时计数并结束吸毒但它给我一个计算错误。 "Cannot assign value of type 'CGPoint' to type 'CGFloat'" 不知道如何解决这个问题。需要帮助
这是函数代码
extension HomeViewController : UIScrollViewDelegate {
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint,targetContentOffset targetContentOffSet: UnsafeMutablePointer<CGPoint>) {
let layOut = self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout
let cellWidthIncludingSpacing = layOut.itemSize.width + layOut.minimumLineSpacing
var offSet = targetContentOffSet.pointee.x
let index = (offSet.x + scrollView.contentInset.left) / cellWidthIncludingSpacing //error Value of type 'CGFloat' has no member 'x'
let roundedIndex = round(visibleWidth)
offSet = CGPoint(x: roundedIndex * cellWidthIncludingSpacing - scrollView.contentInset.left,y: -scrollView.contentInset.top) //"Cannot assign value of type 'CGPoint' to type 'CGFloat'"
targetContentOffSet.pointee = offSet
}
}
看看你的这行代码:
var offSet = targetContentOffSet.pointee.x
Swift 为 offSet
推导出什么类型?可以在Xcode中option-click它来查找,但我们可以看到它必须是CGPoint.x
的类型,即CGFloat
.
从你函数的其余行来看,我猜你希望它的类型为 CGPoint
,因此将其更改为:
var offSet = targetContentOffset.pointee