简体   繁体   中英

iOS Storyboard View Controller constraints do not work properly

I have my ViewController in Storyboard. Everything seems fine in Storyboard, but when I build it on emulator, it shows strange white place on the side. When I changed the background of my View to blue color, I realized that white space was caused by my View. What can cause this kind of problem?

My hierarchy of wiews and constraints: 在此处输入图片说明

My Storyboard view: 在此处输入图片说明

View on emulator: 在此处输入图片说明

Make sure your scrollViews and contentViews LeadingSpace and TrailingSpace are 0, It seems you are leaving 20 pts from LeadingSpace and TrailingSpace.

在此处输入图片说明

Your constraints should look like this:

Make sure you set MainView/ContentView width equals to scrollView.

在此处输入图片说明

What you are messing is, you are setting scrollView width equal to ViewControllers View, remove that constraint and it should work hopefully.

Edit/Update:

I have done demo for test and it is working perfectly fine without any workaround. You can see below screen shot of Storyboard Preview for iPhone 5S and iPhone 6S Plus. ViewControllers view is in Blue color and ContainerView is in Orange color.

在此处输入图片说明

Here are the constraint of scrollView: (While adding constraint make sure you press Alt button)

在此处输入图片说明

And the ScrollViews constraint are as below:

在此处输入图片说明

ContainerView Contraints:

在此处输入图片说明

And the ContainerViews constraint are as below:

在此处输入图片说明

One last thing, inside container view all view's should have top to bottom constraint in order to calculate the height required for scrollView. And also do not create conflicting constraints as - Setting imageView's LeadingSpace and TrailingSpace to ContainerView(SuperView) and at the same time setting fix width.

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