我得到一些错误与以下方法:
1)如何返回screenHeight / cellCount作为第一种方法的CGFLoat?
2)如何在第二种方法中使用等价的ObjC的MIN()和MAX()?
func tableView(tableView: UITableView!,heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
var cellCount = Int(self.tableView.numberOfRowsInSection(indexPath.section))
return screenHeight / cellCount as CGFloat
}
// #pragma mark - uiscrollviewdelegate
func scrollViewDidScroll(scrollView: UIScrollView) {
let height = CGFloat(scrollView.bounds.size.height)
let position = CGFloat(MAX(scrollView.contentOffset.y,0.0))
let percent = CGFloat(MIN(position / height,1.0))
blurredImageView.alpha = percent
}
1:你不能从Int下降到CGFloat。您必须使用Int作为输入来初始化CGFloat。
return CGFloat(screenHeight) / CGFloat(cellCount)
2:使用标准库定义的最小和最大函数。它们的定义如下:
func min<T : Comparable>(x: T,y: T,rest: T...) -> T func max<T : Comparable>(x: T,rest: T...) -> T
用法如下。
let lower = min(17,42) // 17 let upper = max(17,42) // 42