UITextView not visible on UIScrollView

前端 未结 3 1885
难免孤独
难免孤独 2020-12-22 09:12

Ok, so what I have is a UIScrollView that is constrained to all four sides of the main view, centered both vertically and horizontally, and set to have equal width and heigh

相关标签:
3条回答
  • 2020-12-22 09:38

    I have noticed some clues you might have to solve which could probably solve the issue. Since the scrollView is extend by its content's elements, you have to explicitly deal with each element in the scrollView:

    1. For imageView on the top is not well constrained, you need to give it a width or aspect ratio. Fix the imageView issue might solve textview height problem, even it's not still is a good start.

    2. TextView bottom anchor is equal to scrollView bottom anchor, but you have to know textView is also kind of scrollView. So it's not reasonable to constraint each other at same time. Because both of them don't have explicitly height. You can try to type some words in the textView which will at least give it height by its content, then the scrollView can detect the textView bottomAnchor. You might see something then.

    3. Your scrollView's height is equal to view's height is also weird, scrollView shouldn't constraint its height at first. Because it can't be "Scroll"View anymore because it's height is constant. you should let its width equal to view, and let the height be decided by its element's height. Then it will be literally a scrollview.

    Hope it helps

    0 讨论(0)
  • 2020-12-22 09:39

    If you want your scrollView only scrolls vertically you shouldn't set its height equal to its superView so remove it and just set the width to its superView and then it should calculate the height based on the subViews inside it I offer you to drag a UIView in your scrollView and set the constraints to its four sides, and name it containerView , then set its width equal to background view and start laying out your views inside it not inside the scrollview :) If Height of all views in the scrollView is clear, it can infer the scrollView's height in this case you can set a fixed height to your containerView like 800 to get rid of the red lines and check how it works :)

    0 讨论(0)
  • 2020-12-22 09:42

    Avoid putting all your subviews directly inside the scrollView. The autolayout will break apart. You need to :

    • Add a UIView inside the UIScrollView, with constraints 0-0-0-0 to leading-top-bottom-trailing to the UIScrollView, and put all your subViews inside that UIView.

    After that, you need to set the contentSize of your UIScrollView by code.

    Also, you can:

    • add missing constraints to see what is missing.

    • The left panel in UIStoryBoard (Document Outline), you can press the red arrow showing up to see what is missing or conflicting.

    Check out Apple documentation for more details.

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