您的当前位置:首页正文

[8] Swift 函数只执行一次

来源:华拓网
    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)
    }()