I'm presenting a view controller when my view controller is rotated to horizontal.
In my NIb, I have a help button with constraints to margin top and right of 8 pixels each. However, my view controller displays with the button in the top right of a Portait perspective. See image. How do I make this show up in top right in Landscape?
It looks like your screen did not rotate, because the status bar is still in portrait mode. BUT... even if it did rotate, you would probably have problems because the status bar is 8 pts wide, and it is automatically removed in landscape mode.
I'd say (1) set your constraints to put the button 30 or 40 pts from the corner, until you get the rotation stuff worked out, and (2) fix the rotation issues by looking at the settings for which rotations the simulator supports. Normally rotations allowed by xcode (at least for my default swift projects) are left, portrait, landscape, but not upside down.
It happens to me all the time, when using the simulator!
(Assuming that your project is supporting both landscape and portrait mode)
To make sure your device has rotated from landscape to portrait or the other way around, simply rotate it three times instead of once! (Press the ⌘ and then → three times)
Also for your button placement, I would recommend creating a Standard offset to superview's top and trailing margins, without using any particular numbers (Standard pops up when you delete the number in the constraint's Attribute Inspector).
Related
my iOS project consists at the moment of one single UIView or UIViewController. The controller class is called MainViewController.swift.
The view of the view controller has a subview which I've placed at the bottom:
I've set the auto layout option to keep the distance of the subview for every device size the same:
Now I want to keep the sub view always on the short side of the parent view, which means that in landscape mode the sub view show be on the right side of the parent view:
I've checked some tutorials and other posts in the meanwhile:
Ray Wenderlich Tutorial
Stackoverflow Post
At this point it is not clear to my how to realize such a behavior best?
Possibilites I've found to solve the issue:
Vary for traits...but how?
Constraints?
Programmatically - I think this would be the fastest solution, but I really want to use storyboards and learn the correct usage.
Here you can play with size classes and traits. if you want give constraint in portrait mode you have to select compact width and regular height and for landscape compact width compact height.
Please go through following steps to constraint portrait and landscape separately.
1) Please select mode either landscape and portrait from traits.
2) Now, you can constraint each mode one by one. suppose i am giving constraint to red view in portrait mode and i will enable particular constraints for for portrait size class so it will be disable for landscape mode.
3)once we are finished with portrait mode i have switched to compact height compact regular size class which is landscape mode.
4) Now, we can constraint the landscape mode as shown in above screenshot.
As we can see constraints which is light in color are disable for current size class.
So this is how we can constraints landscape and portrait mode separately.
Because there is no size class or trait difference between an iPad in landscape, and an iPad in portrait, you will ultimately have to handle at least some cases programatically. That being the case, you might as well just handle all cases programatically with a method that does something like:
Get current screen size
If width > height, add constraints to center the subview vertical and pin it to the right edge. Otherwise, add constraints to center the subview horizontally and pin it to the bottom edge.
I have a button at the bottom of my view which is constrained as intended on portrait, but when I rotate in simulator, it obviously retains the constraint and shows up before the rest of the content, which is supposed to precede it. I simply don't know how to keep it at the bottom of the view in both orientations.
Bonus question: how to scroll down in simulator?
I am updating my app and want to allow landscape orientation.
I am wondering how I can take two views that are stacked on top of each other (and centered horizontally in container) while in portrait and move them to be side by side in landscape (and centered vertically in container).
I would like the bobblehead to be aligned on the left, and the quote box to be aligned on the right. Both views should take up full height while in landscape.
Here are some screen grabs:
What you want is having different layout when device size is not fit to your view.
In iOS8 you can do it without hard coding it.
Yes just by designing right constraint for right size class(introduce in XCode6)
Here is an example which doing same as you want
Example
Code
Download project
Output
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 ?
I am developing an iPad application with view-based template in landscape mode as it has to share a toolbar to all its views and provide the functionality similar to tabbar.
The problem is that any control added to a portion of the screen on the right side is disabled. For example, if a button is added, the part of it on that portion of the screen doesn't work.
Surprisingly, the width of that portion of the screen is equal to the width of the screen in landscape subtracted by the width of the screen in portrait so I think the problem has something to do with that.
Thanks in advance
I'm betting those controls are outside the bounds of their superview (or the superview's superview, or the super-super-superview, or…). When the view hierarchy does a hit test, it returns nil if the point is outside its frame, so subviews outside the frame can't be hit. Note that views in IB don't have the "clips subviews" option on by default, so it's hard to tell where the view bounds are. Also check the autoresize settings on those views--if one of the containing views isn't set to resize horizontally and it's sized to portrait width in the nib, it won't expand to landscape width when you rotate the device.