I got a strange glitch on iPhone 6 device (only on device. Simulators works fine. And i assume another real devices will have the same problem). Here is the video: https://youtu.be/_s3C1RnPG_I
Also, on iPhone X simulator there is a blank empty space under message sending view,
but i want something like this.
Here is a constraints for message sending view:
Definitely something wrong with bottom constraint but i tried almost all and nothing has helped.
According to Apple -
Interface Builder uses UIView.safeAreaLayoutGuide as a replacement for the deprecated Top and Bottom layout guides in UIViewController. To use the new safe area, select Safe Area Layout Guides in the File inspector for the view controller, and then add constraints between your content and the new safe area anchors. This prevents your content from being obscured by top and bottom bars, and by the overscan region on tvOS. Constraints to the safe area are converted to Top and Bottom when deploying to earlier versions of iOS.
Here is simple reference as a comparison (to make similar visual effect) between existing (Top & Bottom) Layout Guide and Safe Area Layout Guide.
Safe Area Layout:
AutoLayout:
Use this article for calculating size of bars.
First assign Leading, Trailing, Bottom and Height constraints for custom message view according below:
Then edit bottom constraints as below:
Change second item to view.Top & Constant = 44 (height of message view)
Related
I am having trouble pinning the UIButton to the bottom of my UIViewController, (There is a tab bar if that helps).
Here are the constraints of the UIButton.
Originally, it all worked fine, but ever since I added iPad support to the application I have issues. on the iPad the UIButton is pinned to the bottom of the screen, directly above the tab bar. However on iPhone, there is this empty gap at the bottom.
What I Tried
Doing some research I saw that sometimes split view controller causes a grey bar, I added this line of code to resolve it and it fixed the bottom bar , but this constraint issues is still causing me a headache.
self.extendedLayoutIncludesOpaqueBars = true
iPad View Hierarchy
iPhone View Hierarchy
You have an option on Xcode to vary your constraint depending of the size of the screen.
You can create two constraints, one that works on iPad, one that works on "classic" iPhone.
Here, if I create a new constraint during the variation, I can then select on the right window which variation you want the constraint to be installed on.
There is a whole topic about that here
Remove current Constrain and Try unchecking "Constrain to margins" button.
Try setting a constraint to a View instead of a SafeArea
1- Give it a constant height for example 40
2- While setting constraints, uncheck (Constrain to margins)
3- Give it a proportional width constraint with the super view 0.8
Note1: If you don't want to give it a fixed height you can do the same step 3 but with height and not 0.8 but maybe 0.2 to less depending on your design.
Note2: You can use a scroll view, it will make it so easy for you
I will mention right away that I'm not iOS developer and this is first time I'm messing with it because I was asked to update web application inside iOS WKWebView wrapper.
I managed to load the web app inside iOS app but on iPhone X there is always white space on top and bottom. I just learned about constraints and I heard that this is default safe area behaviour. I'm trying to expand my WKWebView past safe area to go all the way to the top notch and bottom home button so that there are no white spaces. Inside Xcode all constraints for safe area object is set equal to superview, following web view container object set equal to superview. But I still have white spaces on top and bottom.
There is also top "View" object which I think is elsewhere known as superview, which when I click on I see the constraints for it set equal to safe area and I can only keep it set to safe area or web view container which itself is set to superview. I find this very confusing. What am I doing wrong here?
I would appreciate help regarding storyboard and not code related as I don't speak Swift.
EDIT: Snapshots of constraints
Web View Container Object: https://imgur.com/GcRFeL0
If you use storyboard, you can do like this:
select this constraint and at the right panel, you should change the Second item form Safe Area to SuperView like below:
modify the Constant value from 44 to 0, like below:
the same operation to other constraints.
I added constraints properly with respect to super view instead of a safe area but still I am facing an issue of grey area on top and bottom of specific screen.it should appear completely on the whole screen at I Phone X. Please follow the screenshot.
Check that you have a launch storyboard and not a fixed launch image
that does not respect the iphone x screen size
Check in your top and bottom constraint properties that they are relative to superview and not to margins (by default xcode 9 adds the constraints relative to margin).
I am working on an iOS application and it will be compatible for all devices iPhone 3.5, 4, 4.7, 5.5 inches and iPad also.
I am designing a screen it has 5 subviews, as i view this screen in different screen it does not resize properly.
I am using Auto-layout to manage that screen and I have set the every possible constraint to manage this screen.I have to manage the Subviews height and width as the devices changes.
Following are the steps taken care by me
1)Set the Equal Height Constraint for all subviews
2)Equal Width Constraint for TopView1 and TopView2 set the High priority and set the proper Horizontal spacing, Leading, trailing edges for these two top spaces accordingly.
3)Equal Width Constraint for MiddleView1 , MiddleView2 and MiddleView3 and set the High priority and set the proper Horizontal spacing for these two and vertical spaces from TOpViews accordingly.
4)Set the Width Constraint for bottomView and set the High priority and set the proper Horizontal spacing for these two and vertical spaces from MiddleViews and bottom spaces accordingly.
Prior to this i have not used auto-layout in such complicated way.
Following are the screen shotes depict my problem.
EDIT:
#Ash Furrow please see attached a screen shotes with constraints.
I am laying out the base screen on Any Width Any Height
Please anybody suggest me how should i manage this view
Hmm. Looking at what you've done and the feedback to your question, everything seems correct.
I think I see the problem. The issue doesn't appear to be with your storyboard (here in case anyone is interested), but rather the use of Xcode. Instead of changing the view controller's simulated "Size" metric, use the Assistant Editor to view a preview of whatever device you want. I've tried that, and ran the code, and in both cases they appear to work.
So to recap, use the Preview in the Assistant Editor instead of changing the view controller's properties to resize a view hierarchy.
I have just started to move my application to autolayout.
I want to give constraint to a label '0' pixel below navigation bar.
I tried but did not found solution.
Here are screen shots.
In storyboard I gave constraint from superview.
In IOS7 it works fine.
But in IOS6 it goes below navigation bar by 64 pixels, as superview starts below navigation bar.
If I could add top constraint for label below navigation bar it will solve the problem. But I cant find how to do it. I searched through few questions. but dint got the answer.
Please help.
Update for iOS 11:
iOS 11 introduces the concept of safe areas, and the burden of container all the content in a visible area is, again, at the hands of the view, rather than a tango of view and controller.
See Apple's documentation here.
When working with storyboards or XIBs, it's as simple as enabling the feature in Xcode. This is backward compatible and should work as expected under iOS 10 and below. In code, you would use if (#available(iOS 11.0, *)) in order to decide whether to set constraints against the safe area guide/anchors or use the legacy guides on older systems.
When using storyboards, you need to add a constraint to the top layout guide. This will take care of your issues, as on iOS6, that is 0pt and on iOS7, it is dynamic. If you are using a nib/xib file, it gets a little more complicated; you need to add the constraint in code. The easiest way to achieve this is to create a constraint with 0 vertical space to top, create an outlet to this constraint in the code and in viewDidLayoutSubviews, update the constant of the constraint outlet to the value of self.topLayoutGuide.length.
You just have to make some modifications in your constraints :
1) Give a height constraint to your label
2) Pin your label to leading view - Horizontal Space Constraint
3) Add a Vertical Space Constraint
3rd step has to be careful [I'm attaching an image for your reference.]
And after doing that, check if the red arrow mark still persist on your View Controller.