When I run the application in the simulator iphonex , I noticied that the UIView does not start from the top. There is some space between my UIView and the topbar of the view. please any help. thank you.
Asked
Active
Viewed 171 times
-3
-
2Can you please provide 1) a screenshot of the bug 2) the code or the storyboard you used to set up the view 3) what you want it to look like – Oscar Apeland Mar 22 '19 at 15:57
-
safe area maybe? – Stefan Mar 22 '19 at 15:57
-
2@Stefan Seeing he has tagget iPhone X that seems likely. I also suspect he doesn't know what safe area is. – Oscar Apeland Mar 22 '19 at 15:57
-
i know what does mean the safe area. just i make constrainst top to safearea = 0 – Moez Mar 22 '19 at 16:18
-
nope, making top constraint to safe area will give you this result you have presented – Stefan Mar 22 '19 at 16:23
-
i did not understand what you say – Moez Mar 22 '19 at 16:58
-
1@Moez if you didn't understand what Stefan said, then you don't understand what Safe Area does. The Safe Area in iPhoneX has margins so the notch doesn't go over the content, but if you don't want those margins, then your constraints should be relative to the superview, not the safe area. There are different resources about it, I like [this explanation](https://medium.com/rosberryapps/ios-safe-area-ca10e919526f), you should also read the [Apple guide](https://developer.apple.com/documentation/uikit/uiview/positioning_content_relative_to_the_safe_area) about it. – Fantini Mar 22 '19 at 17:57
-
Possible duplicate of [Safe Area of Xcode 9](https://stackoverflow.com/questions/44492404/safe-area-of-xcode-9) – Fantini Mar 22 '19 at 17:58
-
1"i know what does mean the safe area" I think you don't. – matt Mar 22 '19 at 19:51
-
@matt yes I know it – Moez Mar 25 '19 at 16:23
-
2If you understand what the safe area is, you are not surprised at what is happening. The top of the safe area is NOT the top of the screen on the iPhone X. It is further down. So your result, when you pin the top of your view to the top of the safe area, is just what you should expect. – matt Mar 25 '19 at 16:29
-
hello please i still have the same problem what must i do please ? – Moez Apr 04 '19 at 16:04
-
You must pin your view to the top of its superview, not to the top of the safe area. – matt Apr 04 '19 at 17:21
1 Answers
0
Something similar happened to me. In the storyboard make sure that there is not Center Vertically in Container (in Size inspector -> constraints -> Align Center to: ) if exist remove it and try to make that view height Equal Height to the ViewController height. Just press Ctr key + drag from your problematic view to the ViewController View, it will pop up a dark menu, pick there Equal Height as described in the image below:

Pedro Trujillo
- 1,559
- 18
- 19