简体   繁体   English

UIView不在UIScrollView中垂直滚动

[英]UIView doesn't scroll inside UIScrollView in vertical

I have UIViewController . 我有UIViewController It has a UIView with three objects( UILabel , UIImageView , UITextView ) inside UIScrollView . 它具有一个UIView ,其中UIScrollView包含三个对象( UILabelUIImageViewUITextView )。 When I try scroll vertical nothing happens. 当我尝试垂直滚动时,什么也没有发生。 I use autolayout. 我使用自动版式。 Before I made it without UIView inside UIScrollView but there is an empty space in the bottom. 在没有在UIScrollView内使用UIView情况下,但在底部之前有一个空白区域。

@IBOutlet weak var scrollView: UIScrollView! {
    didSet {
        scrollView.delegate = self
        scrollView.scrollEnabled = true
        self.scrollView.frame.size = scrollView.contentSize //12
    }
}

在此处输入图片说明在此处输入图片说明

The problem is that you're setting the scroll view's frame size to be equal to the scroll view's content size. 问题是您正在将滚动视图的框架大小设置为等于滚动视图的内容大小。 A scroll view will only scroll if its content is larger than its frame. 滚动视图仅在其内容大于其框架时才滚动。 Instead, set the scroll view's frame size to match the container view's size, and set the content size's height to the bottom of the text view. 而是,将滚动视图的框架大小设置为与容器视图的大小相匹配,然后将内容大小的高度设置为文本视图的底部。

if you are using auto layout no need to set the frame of scrollview, give your view which is subview of scrollview height constraint eg 800 and set scrollview and outer view width constraint to match the width for each device and set scrollview frame using autolayout, this will start scrolling. 如果您使用自动布局,则无需设置scrollview的框架,请提供您的视图,该视图是scrollview高度限制的子视图,例如800,并设置scrollview和外部视图宽度限制以匹配每个设备的宽度,并使用autolayout设置scrollview框架将开始滚动。

refer this link for further details 请参阅此链接以获取更多详细信息

When we are using scrollview with auto layout it little bit confuting but it you see scroll view's behavioral then you will easily get idea about it. 当我们将scrollview与自动布局一起使用时,它有点混乱,但是您看到了scroll view的行为,那么您将很容易了解它。

for scrollview set constraint as 0 for four sides. 对于scrollview,将四个侧面的约束设置为0。 then check out the size of you view (which you added in scrollview) and set it to scrollview content size. 然后查看您查看的大小(您在scrollview中添加的大小)并将其设置为scrollview的内容大小。 for view set equal weight constraint with scrollview width. 对于视图,设置相等的权重约束与scrollview宽度。

I hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM