Storyboard UIScrollView contentSize?

后端 未结 8 1732
-上瘾入骨i
-上瘾入骨i 2020-12-14 20:20

I feel like I have touched on every single possible cause for stopping this, but I have a UIScrollView in my Storyboard hooked up with an outlet and in the viewDidLoad I set

相关标签:
8条回答
  • 2020-12-14 20:38

    Trip14's answer worked for me. In swift I coded it as:

    override func viewDidLayoutSubviews() {
    
              (self.view as! UIScrollView).contentSize = CGSizeMake(600, 600)
            }
    
    0 讨论(0)
  • 2020-12-14 20:38

    This seems to be a similar issue. Other Story

    It might be an issue with auto layout or constraints in the storyboard.

    0 讨论(0)
  • 2020-12-14 20:39

    Check these

    • User Interaction enabled
    • Outlet connected
    • Included contentsize greater than bounds
    • scrolling Enabled

    eg

    scrollView.contentSize = CGSizeMake(320, 640);
    

    My storyboard looks like this for scrollview [working]

    enter image description here

    0 讨论(0)
  • 2020-12-14 20:40

    the best way with the storyboard.:

    0 讨论(0)
  • 2020-12-14 20:44

    use ViewDidLayoutSubview

    - (void)viewDidLayoutSubviews
    {
        [_scrollView setContentSize:CGSizeMake(320, 500)];
    }
    

    UIViewController's method invoke sequence is as below

    • awakeFromNib
    • viewDidLoad
    • viewWillAppear
    • viewWillLayoutSubviews
    • viewDidLayoutSubviews
    • viewDidAppear
    0 讨论(0)
  • 2020-12-14 20:54

    I had exactly the same line of code in viewDidAppear and it did not work

    Moved it to viewDidLayoutSubviews and it worked correctly.

    [scrollView setContentSize:CGSizeMake(320, 500)];
    

    Thanks trick14 for the answer.

    0 讨论(0)
提交回复
热议问题