In my application i have a screen which contains close button on top and program information at bottom and both trailing,leading,bottom and top constraints related to safe area.
Button width and height is 1:1. Program info area height is 0.25 of view height. In run time adding avplayerviewcontroller view on screen whose height is 75% of self.view.It's working fine in all device except iPhone X. If i launch app in landscape then alignment is fine and if I change orientation I can see 44 pixels as x value. If I launch app in portrait first then portrait orientation values are correct if I change orientation to landscape then 44 pixels top(y) value is adding. I am not getting how to fix this issue. Please guide me.
[![enter image description here][1]][1]
I guess your problem is that you have defined constraints in percentages, which might be an issue. When you rotate the screen the mid section might be too small. Have you tried the rotated layout in interface builder to see what is happening? Defining layouts with constraints is relatively easy in interface builder and you can test the layouts as well.
If you programmatically set the constraints, it is hard to find out where it went wrong. If you have one ambiguous constraint, the whole screen can be weird.
If you need to make programmatically set constraints, you should make a test setup in interface builder and implement the good setting in the program code, when everything works as planned.
I have checked your storyboard and I think the issue might be that you have two safe area defined. One outside the containerview and one inside. What you put inside the container view, might be wrongly calculating the constraints inside.
Try to take out this checkbox and try it again.
Related
My GUI looks like that:
Image
I don't really know how to set the constraints of the image view in the middle properly.
It works in portrait mode if I set constants but if I rotate the device it doesn't work anymore because the constant value is wrong for landscape.
Do you know how to solve that?
When you see a red-lined constraints that means the there is at least one missing constraint. When adding constraints to a component it should cover the whole frame of it (size: height/width and origin: x/y). If you want to let the height/width of the imageView dynamic (based on screen size), then you should add Equal Widths and Equal Heights constraints between the imageView and view container.
Also, in xcode 8, you can easily choose the desired size class, by choosing the device and its orientation. So, let's assume that you want to setup the constraints for all the iPads in landscape mode, in storyboard you should pick -for example-:
Also, you might want to check this video from WWDC 2016.
Hope this helped.
When I add an image and constraint it to remain in the top-half center of the screen; I would like it to work with all iPhones except it doesnt,.the problem is it only works with iPhone 4 portrait and landscape that I have but when I change the iPhone to iPhone 6 it doest stay in the middle, does anyone know why?
To geta an element in the middle of the screen here are a few tips:
Ensure you drag the object in to the middle of the screen (Horizontally). You will notice guideline's appear up the screen.
Set the constraints on the item which include 'Set Horizontally in container' & Set a top constraint only (You may want a height wand width also, experiment with this.
For an image make sure that you have set your fill property for your application. (Aspect Fill etc)
A good tip to get used to auto layout is to set your view controller to iPhone 4 and design on that (With constraints of course)
Auto-Constraints are rubbish, create them yourself!
I have a simple layout with multiple views and constraints to position and size them as I need. When I deploy the app to a simulator or device, the X, Y and Widths of all the views have the proper sizes. The Height on the other hand is always 0. All the views have proportional heights according to the super view.
Now, if I flip the orientation to Landscape and then back to portrait, everything shows up properly (the heights are no longer 0).
I've used the same logic with proportional heights previously, and I started seeing this problem with newly created view controllers after updating to Xcode 7.
EDIT You can get the .xib from: http://1drv.ms/1M81EUQ
you have to Set different view update method call regarding the orientation changed if you use auto mask resizing or used autolayout to fix this .
Your .xib was configured with Size Classes enabled, but your views and constraints were all configured to only be applied for Compact width, Regular height.
I went through and changed the views and constraints to apply to Any width, Any height, and this resolved the issue with landscape layouts.
Download the modified .xib file here
I recommend using Xcode 7's Preview Assistant View when working with Autolayout, as it will let you see multiple devices, in multiple orientations at the same time. This really helped in this case with showing that the layout was fine in portrait, but not in landscape.
This is what I saw in your .xib as you provided
And with the changes in my .xib
How could this have happened? One way is that you may have accidentally set the storyboard editor to a specific size class. If you see a blue border at the bottom of the editor, anything you add will be configured to be only installed for that specific size class. You can click on the size class shown to change it out to w Any h Any to return to the default mode.
Maybe striving for a "warning free" project is futile, but I am nervous enough about Adaptive Layout/ AutoLayout that I am compelled to try and squash these warnings.
I have a uiview that I want to be dynamically sized based on the portrait screen width. I have my app set in the Build Info for Universal, Portrait only (and upside down). I have constrained the uiview the following ways:
Aligned the view's Center to Superview's center X
Made the view's width proportional to the Superview's width
Gave the view an aspect ratio constraint of 1:1
Given the view a vertical constraint to the superview's top
For details please see the screenshot below.
So now I get the warnings about the view's "frame being different at run time", in particular the size and position at runtime versus what is in the canvas. Not sure why Xcode "cares" about the canvas where the class sizes are set to Any height and Any width. I thought the whole point of Adaptive layout is that sizes and positions are resolved at runtime based on the devices screen size and orientation.
If I breakdown and let Xcode "Update frames"... yes the warning goes away, but with the super large views it is virtually impossible to work graphically in the tiny canvas in a WYSIWIG fashion. Any solution here to getting rid of the warnings without creating oversized views that make working inside the canvas nearly impossible?
To get rid of the warning, and let the constraints place the views "correctly", just select the view that is giving the warning, press the little triangle thing in the bottom right corner of the storyboard:
And then select "Update frames" for "All Views in Container"
(I wish there was some way of doing this to a whole storyboard. At least I haven't found it)
Select a view and press
Option + Command + =
This will update the frame size. Repeat for all offending views. It doesn't take that long, especially if you find them by clicking on the error messages.
Thanks to this answer for the idea.
Notes
After updating to Xcode 8, and choosing some View as device, I was getting this error. The menu is different than in Xcode 7, so #Spoek's answer was no longer working. Also clicking Update or Reset was not working for me.
Update
Update Frames now has its own button. That's why I missed it before.
You can change simulated metrics size for example to 4-inch iPhone!
Or Freeform and then change the size to what suits you best.
I was getting this error on static tableview cells. I unchecked the Automatic option and the warnings went away
Oh, I am having trouble with AutoLayout in IB(xcode 5, ios7), an IPad project.
Here is a view hierarchy in my project.
UIViewController->UIView->UITableView->UITableviewCell->UILabel。
And I add some constraints to UILable, (1.pin height, 2. Pin leading space to superview 3.pin trailing space to super view, 6 pin top space to superview.). But when I look in the portrait mode, I think it should change its' width to keep 2 and 3 constraints, but it didn't, can anyone give me a suggestion what should I do.
Thanks a lot!
Here is my screen shot in portrait mode and landscape mode.
I suppose I'm right when I say that you obtain the second screenshot when you select Landscape for the Orientation in the Simulated Metrics of your view controller. As the title of this section suggests, it's a simulation (might be different at run time). The warning message you have might be saying Frame for **** will be different at run time. Have you tried to run your app? Have your labels wrong positions/sizes ?