简体   繁体   中英

Scrollview is not scrolling using autolayout though I have added proper constraints

I have got a layout in following form

I have got the views in following hierarchies.

  ---View
    -------TopView
    ---------Label
  --Scrollview
  ---------ContentView
  ----Buton

The content view has got the constraing attributes as in the following picture,

在此处输入图片说明

The problem is that scrollview is not getting scrolled. Am i missing any layout constraints from being set? scroll view is of width 374 and height 534. Contentview is of width 334 and height 494

Every time you try to add the scroll view on something like submit application/ form then remember these steps:

  1. On base view add a scroll view with frame exactly equal to base view

  2. add top left bottom and right constrain (should be 0 each)

  3. take another view with equal frame to scroll view and set 0 constrain to default four constraint type ie TOP Bottom trailing leading.
  4. Also give equal height and width to base view constraint.
  5. Now try to add a button just above bottom on 2nd view
  6. give following
    constrain to button : Horizontally center, width , height ,
    bottom.
  7. Try to run on simulator You should be able to scroll till button.

Have you set ScrollView contentSize ?
Please check you have set scrollable height.

Eg.

 scrlVIewSignUp.contentSize = CGSizeMake(self.view.frame.width, 1000)  

Where 1000 is the approximate height.(please set height as per your requirement)

I assume you are running into issues with the contentSize. Check out this .it is about how to handle the contentSize when using a "pure" AutoLayout approach. The gist of it is that your constraints implicitly define the content size. You NEVER set it explicitly when using AutoLayout.

it also have, attached example project at the end of the blog post to demonstrate how it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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