Universal app : LaunchScreen not respecting interface builder constraint when launching in landscape - ios

I have some troubles with the LaunchScreen.storyboard.
My app is a Universal App, default orientation is portrait but landscape is also allowed.
My LaunchScreen is very simple.
A UILabel with 2 constraints :
Align leading to Safe Area (with constant = 30)
Top space to Safe Area (with constant = 30)
When I check my LaunchScreen inside XCode with simulated traits (iPhone XR, iPad, Landscape, Portrait…) everything looks fine.
When I launch the app in portrait orientation everything looks fine.
Then I turn the simulator (or real device) to landscape and re-run the app.
This time the UILabel doesn't respect it's constraints. The label is touching the black notch and the top space seems twice the defined size.
Do you have the same problem ? How can I fix it ?

Apple describes this in their documentation as follows:
At launch time, apps should always set up their interface in a portrait orientation. After the application(_:didFinishLaunchingWithOptions:) method returns, the app uses the view controller rotation mechanism described above to rotate the views to the appropriate orientation prior to showing the window.
So I believe the behaviour you're after isn't particularly supported by Apple I'm afraid. As a side note, I'm not entirely sure how they support it on iPads.

Apply constraints to your UILabel as per my below screenshot :-
Also, in your project Target set Deployment Info :-
If you want to change UILabel frame, then ask me.

Related

Lauchscreen.storyboard landscape splashscreen

I am using lauchscreen.storyboard for splashscreen in my iOS application. I have added splashscreen image in the storyboard. When app is lauchning, portrait splashscreen is coming correctly. But, when opening app in landscape mode, blue color appears in both right and left side of the splashscreen.
I tried setting different splashscreen image by adding variation. But, this storyboard takes any one portrait or landscape image only.
Let me know how to set two images in storyboard, one for portrait and one for landscape or the best practice to set splashscreen for both portrait and landscape orientation. I couldn't find any solution for this in the web though it seems to be a simple problem.
Setting the same launch image for both orientations:
Add an image to your LaunchScreen.storyboard's main controller's view and constraint all edges to superview (not safe Area)
Note: to change a constraint that is referencing SafeArea you can double click it on the inspector and change the respective item. Here are some screenshots for reference
Set the image's content mode to something that scales appropriately (scale to fill or aspect fill for example)
The setup should look like this (you can enable the previews on the right by clicking the assistance editor and switch from Automatic to Preview):
Setting different launch image depending on orientation:
Click on the + button next to your image
Add a customization for regular width & compact height
Your setup should look like this:
Update: What about the iPad?
Unfortunately, it seems that (at least up to Xcode10.1) is not possible to customize your launchscreen the same way for iPad, for a couple of reasons. The main one is that iPads are Regular x Regular for both portrait & landscape. The other reason is that you cannot use custom classes in your LaunchScreen.storyboard. Because if you could, you could subclass UIImageView and override the traitCollection with something like this (essentially would be treating the iPad as an iPhone sizeclass-wise):
override public var traitCollection: UITraitCollection {
if UIDevice.current.userInterfaceIdiom == .pad && UIDevice.current.orientation.isPortrait {
return UITraitCollection(traitsFrom:[UITraitCollection(horizontalSizeClass: .compact), UITraitCollection(verticalSizeClass: .regular)])
}
return super.traitCollection
}
By the way, you can still use code like the above in the rest of the application for your windows/views if you want to solve similar problems.
I know that this is not what you were looking for in the answer, but I am afraid that (for now), you'll have to use static images in your Assets for handling iPad.
By default use portrait, Add variation to your image for landscape version with these selections.
Update your landscape picture here.
personally, I also recommend you to use AutoLayouts.
Run the app.
Example - Results -
how to set two images in storyboard?
iOS has sizeClass for almost anything you can see. You can choose image, color, etc for any situation you need based on size of the main window of your application (Not only orientation of the device)
It's more convenient. Because maybe the device is in landscape mode but it's in split screen of iPad 🤷🏻‍♂️. So let OS decides what is best match for the size situation.
- Size Classes in interface builder
[
- Working example:
Make use of Vary for traits as shown ion screenshots. I have tried this and has worked for me.

IB Storyboard for App Extensions: iPad Icons Not Present, Sizes Don't Change, Orientation Not Working

I need to update a 3 year old iPhone-only, portrait only (NOT universal) camera/photo app that worked with iOS 8 that contains a Share extension that now (with 10.0???) crashes at times (but works many other times), and I'm trying to debug the issues and update to iOS 9.0.
The first issue I found and fixed was the lack of Privacy strings for access to the camera and photo library.
But I also found that the extension does not work with Photos on an iPad with layout issues (in the Simulator so far). As the docs say, extension targets must be made for iPhone/iPad and my build setting for the target extension are set to 1,2, and I use Auto Layout.
The storyboard, the Extension scene, a View Controller Scene, all view controllers, views and subviews all are set for Auto Layout as well as Safe Area Layout Guides, but the only devices shown in IB are iPhones with no iPads available, when selecting other devices no change is seen in size, and the iPhone is constrained to portrait mode.
I've tried setting the main app as Universal, allowing every orientation, building, and still no iPad icons in IB to test the UI for the extension (and trying to get Landscape mode in IB doesn't work either).
Is there a way to get IB to show and allow iPads/iPhones, particularly iPads, and change orientation during development for app extensions?
Selecting "Use Trait Variations" made the iPad icons appear.

Splash screen requirement iOS app - Portrait

I am developing an iPhone app in Xcode 7 which will only open in portrait mode. My question is do I need to provide the launch/splash/default screen also for landscape mode or providing it in the various portrait mode sizes will be sufficient?
I think adding only the portrait ones should work for you. Hope you are using xcassets for managing splash screens. There, You can select the orientations and devices which you want to support. Here is a screenshot.
NOTE: This is from Xcode 6.4. Hope it's something similar in Xcode 7.
Design the LaunchScreen.xib file to look as your desired splash screen. Set proper constraints to your design elements/views. And thats it! It will appear as expected on any orientation.
For example:
If you want your app logo to appear in the center on app launch as splash screen, set your logo in a image view at center, give constraints for horizontally centering, vertically centering and height and width constraints. Now run the app by keeping simulator in various orientations and your launch screen will appear same in all orientations.

Why is iOS simulator displaying blank screen when I rotate device?

Getting through some introductory swift and playing with Xcode and I basically just have a page with some color squares, background color etc. Doesn't do anything. Problem is when I compile the code it will run in simulator just fine and show everything perfect, BUT when I rotate the device, everything disappears and it only gives me a blank white screen. Rotating right or left does it. The only view that shows it is the original upright view (for all iPhone devices that I tested on through the simulator).
Xcode 6.1.1 and iOS Simulator 8.1 are being used on my MacBook Air with OSX 10.9.5.
In the App general page, I have already checked under Deployment info that Landscape Right and Left are both checked on. Storyboard is set on Any H and Any W.
I'm not sure what I'm doing wrong and it has been pretty difficult searching since I'm still new to iOS development I'm not sure I'm using the right words or whatever because I can't find an answer.
Summary:
App displays properly in iOS Simulator, Portrait View but no other views work and will display blank white screen instead.
In order to see if your views are actually being drawn and just off screen as others have suggested capture the view hierarchy. Go to 'debug' in the menu, then in 'view debugging' click capture view hierarchy. This will pause your app and create a 3D representation of all view on your screen which you can move around by clicking and dragging.
Are your views actually being drawn? If yes are they drawing off screen? If yes then you need to fix your constraints.
It sounds like you haven't set your constraints appropriately. Try setting the top and leading constraints for each of your views to something less than 320 (should cover all device sizes). Fix your warnings, then try again. I believe the views are simply off the screen.
You don't have the correct auto-layout UIConstraints set in interface builder. Check the document outline view in interface builder and ensure that you have appropriate constraints set on each view.
Auto Layout issues occur when you create conflicting constraints, when you don’t provide enough constraints, or when the final layout contains a set of constraints that are ambiguous.
Check this Apple documentation out, it will show you step by step how to resolve your (common) issue.

How can I change a window orientation to landscape in XCode 4 Interface Builder?

I appreciate I'm probably missing something basic here, but...
My iPad app will only support landscape mode, and has a MainWindow.xib Window that I'd like to work on in landscape mode in XCode 4, however the pull-down menu to change this (Simulated Metrics -> Orientation) is always grayed out.
I notice that Views can be rotated just fine, it's only Windows that can't be rotated in XCode 4 using this setting.
Is there a workaround for this, or do I have to put a View on top of the MainWindow in order to rotate it?
I think it's because apps always starts up in portrait and then rotates to appropriate oriantations. From the UIViewController docs:
Note: At launch time, applications should always set up their
interface in a portrait orientation. After the
application:didFinishLaunchingWithOptions: method returns, the
application uses the view controller rotation mechanism described
above to rotate the views to the appropriate orientation prior to
showing the window.
So you'll need the UIViewController magic for the simulated metrics to make any sense. If you used the "Window-based application" template as a starting point for your project try the "View-based application" template instead.

Resources