[8] Swift 函数只执行一次

来自官方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)
    }()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,267评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,916评论 25 709
  • 一直觉得自己是一个脆弱到无法在这个世界上生存下去的人,小时候,为了世俗的标准,好好学习,有出息这些努力奋斗着证明自...
    爱哭的小魔鬼阅读 364评论 0 0
  • 你也许不会相信,我常常想象你是多么美好,多么可爱,但实际见了你面的时候,你比我想象的要美好得多,可爱得多。 ...
    Fnn丶J阅读 1,605评论 0 0