UIScrollView
scrollView.frame
scrollView.isPagingEnable = true
scrollView.contentSize = CGSize() //设置滚动范围
scrollView.delegate = self
pageControl.frame
pageControl.numberOfPages
pageControl.currentPage
pageControl.addTarget
@objc func PageControlDidChanged() {
let crtPage = scrollView.currentPage
var frame = scrollView.frame
frame.origin.x = frame.size.width * crtPage
frame.origin.y = 0
scrollView.scrollRectToVisible(frame, animated: true)
isPageControlUsed = true
}
func scrollViewDidScroll() {
if(!isPageControlUsed) {
let pageWidth = scrollView.frame.size.width
let page = floor(scrollView.contentOffset.x - pageWidth/2)/pageWidth + 1
pageControl.currentPage = page
}
func scrollViewDidEndDecelerating() {
isPageControlUsed = false
}
}
网友评论