<分区>
我正在尝试找出如何使所选页面的点比其他页面稍大,如下所示:
第 1 页:
第 2 页:
我可以更改所有点的点颜色、大小、背景等,但不能更改当前页面的特定点。
如何仅更改当前页面的点大小?
这可以是 Swift 或 Objective-C。
<分区>
我正在尝试找出如何使所选页面的点比其他页面稍大,如下所示:
第 1 页:
第 2 页:
我可以更改所有点的点颜色、大小、背景等,但不能更改当前页面的特定点。
如何仅更改当前页面的点大小?
这可以是 Swift 或 Objective-C。
最佳答案
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let x = targetContentOffset.pointee.x
pageControl.currentPage = Int(x / self.frame.width)
// on each dot, call the transform of scale 1 to restore the scale of previously selected dot
pageControl.subviews.forEach {
$0.transform = CGAffineTransform(scaleX: 1, y: 1)
}
// transform the scale of the current subview dot, adjust the scale as required, but bigger the scale value, the downward the dots goes from its centre.
// You can adjust the centre anchor of the selected dot to keep it in place approximately.
let centreBeforeScaling = self.pageControl.subviews[self.pageControl.currentPage].center
self.pageControl.subviews[self.pageControl.currentPage].transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
// Reposition using autolayout
self.pageControl.subviews[self.pageControl.currentPage].translatesAutoresizingMaskIntoConstraints = false
self.pageControl.subviews[self.pageControl.currentPage].centerYAnchor.constraint(equalTo: self.pageControl.subviews[0].centerYAnchor , constant: 0)
self.pageControl.subviews[self.pageControl.currentPage].centerXAnchor.constraint(equalTo: self.pageControl.subviews[0].centerXAnchor , constant: 0)
// self.pageControl.subviews[self.pageControl.currentPage].layer.anchorPoint = centreBeforeScaling
}
关于ios - 当前页面的 UIPageControl 点大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51303719/