来自官方Demo PageControl 的代码片段:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
/**
Setup the initial scroll view content size and first pages only once.
(Due to this function called each time views are added or removed).
*/
_ = setupInitialPages
}
// MARK: - Initial Setup
lazy var setupInitialPages: Void = {
/**
Setup our initial scroll view content size and first pages once.
Layout the scroll view's content size after we have knowledge of the topLayoutGuide dimensions.
Each page is the width and height of the scroll view's frame.
Note: Set the scroll view's content size to take into account the top layout guide.
*/
adjustScrollView()
// Pages are created on demand, load the visible page and next page.
loadPage(0)
loadPage(1)
}()