简体   繁体   English

UIscrollview无法正常工作的iOS Swift

[英]UIscrollview not working ios swift

在此处输入图片说明

I tried to implement thorugh this method: 我试图通过这种方法来实现:

override func viewDidLoad() 
{
        super.viewDidLoad()
mainScrollView.contentSize = CGSizeMake(self.view.frame.size.width, 530);
          // Do any additional setup after loading the view.
}

but then also scrollbar not working properly. 但是滚动条也无法正常工作。

self.scrollView.contentSize = self.scrollView.superview!.bounds.size

  1. First, you have set scrollview(0,0,600,600) 首先,您已设置scrollview(0,0,600,600)

  2. Setting the autolayout for scrollview leading,trailing,top,bottom. 为scrollview的前,后,上,下设置自动布局。

  3. Second, you have set contentview inside your scrollview(0,0,600,600) 其次,您已在您的scrollview中设置contentview(0,0,600,600)

  4. Setting the autolayout for contentview like leading,trailing,top,bottom. 设置contentview的自动布局,例如前导,尾随,顶部,底部。

  5. Third, Setting contentview width is Equal to superview width. 第三,设置contentview宽度等于superview宽度。

  6. Fourth, Setting contentview height. 第四,设置contentview的高度。

  7. It's working perfectly. 运行良好。

In this case your mistake is you should not give content size. 在这种情况下,您的错误是您不应提供内容大小。 And for automatic scrolling you can do auto-layout constraint. 对于自动滚动,您可以执行自动布局约束。

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

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