[8] Swift 函數(shù)只執(zhí)行一次

來自官方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)
    }()
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關注 消息 iOS 第三方庫、插件、知名博客總結 作者大灰狼的小綿羊哥哥關注 2017.06.26 09:4...
    肇東周閱讀 12,252評論 4 61
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,532評論 25 708
  • 一直覺得自己是一個脆弱到無法在這個世界上生存下去的人,小時候,為了世俗的標準,好好學習,有出息這些努力奮斗著證明自...
    愛哭的小魔鬼閱讀 362評論 0 0
  • 你也許不會相信,我常常想象你是多么美好,多么可愛,但實際見了你面的時候,你比我想象的要美好得多,可愛得多。 ...
    Fnn丶J閱讀 1,601評論 0 0