我正在尝试测试偏移量并在滚动结束后计算当前页面.
我只需要将此行更新为swift 4?
let pageWidth: CGFloat = CGRectGetWidth(scrollView.frame)
Run Code Online (Sandbox Code Playgroud)
'CGRectGetWidth'已被属性'CGRect.width'取代
//MARK: UIScrollViewDelegate
override func scrollViewDidEndDecelerating(_ scrollView: UIScrollView){
let pageWidth: CGFloat = CGRectGetWidth(scrollView.frame)
let currentPage:CGFloat = floor((scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1
// Change the indicator
pageControl.currentPage = Int(currentPage);
}
Run Code Online (Sandbox Code Playgroud)
'CGRectGetWidth'已被属性'CGRect.width'取代
scrollView.frame返回一个CGRect.所以你可以使用的width属性CGRect
像这样:
scrollView.frame.width
Run Code Online (Sandbox Code Playgroud)
这是一个需要解决的简单问题,当您不确定时,应该首先参考文档.在这里,您尝试获取CGRect的宽度,因此请检查CGRect文档,看看它是否有办法访问大小/宽度.
| 归档时间: |
|
| 查看次数: |
4457 次 |
| 最近记录: |