Why won't UIScrollView scroll fully after adding objects? Using storyboard, ARC, and Xcode 4.5.2

前端 未结 3 1732
一生所求
一生所求 2020-12-29 14:52

So, I know there are similar questions to mine, but maybe not exact (so please don\'t mark me down -- just warn me or something). I have searched for days for the solution t

相关标签:
3条回答
  • 2020-12-29 15:14

    After days of research, it's funny I actually found the solution just minutes after posting this question! So, for my situation I simply had to add this bit of code, and it worked:

    - (void)viewDidLayoutSubviews
    {
        [super viewDidLayoutSubviews];
        [self.scrollView setContentSize:CGSizeMake(320, 808)];
    }
    

    It seems to be working perfectly now. Please, anyone, let me know if this is a poor way of doing it, because I'm new to this and I would love any help. Otherwise, I'll leave it and hope this can help other people! Thanks!

    0 讨论(0)
  • 2020-12-29 15:19

    SOLUTION with Storyboard + Autolayout (no code):

    Vertical scrolling example that starts from top-left corner:

    • Set the top+leading constraints of the first object (subview)
    • Chain up every object till the last one
    • The most important - set the bottom constraint to the scroll view so it's hooked up top to bottom.
    • Set the width of the scroll view - either a specific "magic number" or a better way - connect the trailing constraint of a subview that has a set width - if there's non I usually set a label's width = screen width - side paddings => standard(20)+UILabel(280)+standard(20) - this way the scroll view knows exactly its content's width, otherwise you'll get an "ambiguous width" warning.

    *Needs constraints' adjustments if horizontal scrolling is desired.

    0 讨论(0)
  • 2020-12-29 15:36

    your scrollview's frame is not the scrollable size.

    Check out contentSize

    Set frame to its superview.bounds then set content size to the scroolview's scrollable area.

    Also I dont know that the background will scroll.

    You will want to add subview's to the scrollview itself.

    It should scroll its own subviews. but it will not scroll itself :)

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