Launch screen.storyboard for Portrait and Landscape vs split screen - ios

I have to implement split screen functionality for the new iPad and I got a workaround from Apple's doc to support the same in my app: https://developer.apple.com/library/prerelease/ios/documentation/WindowsViews/Conceptual/AdoptingMultitaskingOniPad/QuickStartForSlideOverAndSplitView.html#//apple_ref/doc/uid/TP40015145-CH13-SW1
In this doc, check the 2nd point:
Provide a LaunchScreen.storyboard file (instead of a .png image file
as you did in iOS 7 and earlier)
This is why I have to use Launch screen.storyboard. Now, the split over works perfect but for my app I have separate Launch screens, Default-Portrait and Default-Landscape. But now I have taken storyboard, I am unable to customise launch screens for different orientations. And even I can't code for the same in Launch screen or it gives me error.
Further, I have tried using size classes to provide separate imageviews for both orientations but I got no success.
It would be great help if anyone suggests me how to implement Launch screen.storyboard for Landscape and Portrait with different images.

You can add a UIImage to your launch screen. Once you've done that and set the constraints to fill the width and height then add an image to your asset catalogue.
On the properties of the image within the catalogue set the 'width class' and 'height class' to 'Any & compact'. Then you'll have spaces for images for Any and compact height (landscape) and Any and compact width (portrait). The just put your artwork in to the appropriate artwork placeholders and use that image on your storyboard.
I believe that will then choose the appropriate artwork for you depending on how the device is held when the app launches.

Related

Different background Image for Splash Screen for iPad for Landscape & Potrait Mode in LaunchScreen.storyboard

I need to set a different background image for iPad for both Landscape & Portrait mode in LaunchScreen.storyboard. I am unable to do that using size-classes as both of them have Regular-Regular size classes. Is there any way to do so? I have other UIKit elements in the LaunchScreen.storyboard as well. like another Imageview and Labels.
you can follow this answer
You can use a single Storyboard to load different Launch images for
iPad and iPhone. In your LaunchScreen.storyboard, go to the Attributes
Inspector of the ImageView where you set the image. Set launch image
for iPhone in Image field. There is a plus sign near the "Image"
field. Click on it and change the Height from Compact to Regular and
click Add Variation. Another field is created as wR hR. Add the launch
image for iPad there. Thats it. Now it loads launch image based on
your device.

Launch screen not working properly

My application supports both orientation landscape and portrait and here i am using launch screen for splash screen then dragged uiimageview and pined trail, lead, bottom, top...what are all the sizes required to add? should i use image assets? Do i have to create two different image? I am using two different image for iPhone and iPad by using size class, Its stretching when iPad runs on landscape mode.
I am referring this https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/launch-screen/
Here how to set image for landscape and portrait and sizes?
We know how to use launch image using asset catalog.
For iPhoneX design gets collapsed, many people suggested us to use launch screen storyboard, then iPhoneX issue went away..
Thanks in advance...
Here is good Apple document answering your question: Launching your iPhone Application in Landscape
Very concise, this document says
Set launch image for either Portrait mode or Landscape mode. Choose orientation of launch image according to your requirement for Application Launch. Do not use static launch image, if your application supports both orientation.
Launch Images
Launch images for iPhone apps are always sized to match the dimensions of the screen in portrait orientation. For applications that launch into landscape orientation, you should use your preferred graphics editing software to rotate the content of the launch image while keeping the image's size consistent with a portrait launch image (height > width).
Avoid using asset catalogs to manage the launch images of landscape applications.
Except for launch images used by the iPhone 6 Plus, asset catalogs assume that all iPhone launch images are for the portrait orientation. When your application is compiled, entries for each launch image are added to the compiled information property list under the UILaunchImages key. The value for the UILaunchImageOrientation key in each of these entries is always Portrait. These entries are then ignored at launch time because the value of Portrait for the UILaunchImageOrientation key does not match the launch orientation (Landscape Left or Landscape Right). The result is a blank screen during launch as the system cannot find an appropriate launch image.
Instead, you should use a Launch File if your application only supports iOS 8 and above. Otherwise, you will need to add your launch images as resources to your project and then add the UILaunchImages key to your application's information property list. Be sure to disable use of the asset catalog for managing the launch images by selecting 'Don't use asset catalogs' from the Launch Image Source menu under the General tab of the project editor for your applications' target.
It’s best to use an Xcode storyboard for your launch screen, but you can provide a set of static images if necessary. Create static images in different sizes for different devices, and be sure to include the status bar region.
Static Launch Screen Images
Here is dimension table for static launch screen image for both orientations:
How to set landscape static image?
Enable Landscape launch screen image support from your image assets
(Image) Assets.xcassets >> Launch Image >> Attribute Inspector >> Enable Landscape (tickmark) >> Set Landscape images
Here is nice tutorial for the same: Customizing LaunchScreen.storyboard
Set image with size of 1125 × 2436 for iPhone X.

How do you set up 'image sets' to match launchImage files for all devices?

NOTE: This question is NOT related to launch image storyboards.
INFO: BG Buddy is a landscape only app. The launch screen uses images in a launchImage.xcassets file.
The launch image transitions to a UIViewController containing a full screen UIImageView with the same BG Buddy Background image as used in the launch image, and some textual UIButtons. This gives the impression that the buttons appear on top of the background image after a short time when the app has loaded.
Here is how the BG Buddy Background image set has been set up since the app’s release. Transitions from Launch Image to UIViewController work perfectly on iPad, iPhones 5,6,7,8 and 6,7,8 Plus.
The iPhone X and the iPhone Plus both seem to use the iPhone 3x image slot but both have very different dimensions. I’ve opened up the other size classes slots and tried to find a place with much confusion and no success. NOTE: All iPhones apart from the iPhone Plus use compact width/compact height size classes when in landscape. The iPhone Plus uses regular width/ compact height in landscape orientation.
So how do you set up 'image set' files to match launchImage files for all devices?
At the moment I can either have a good iPhone X transition or a good iPhone Plus transition but not both.
Is my only option to try to detect if it’s an iPhone X (or iPhone Plus) and swap the images programatically?
So here's the solution for a landscape only app. Hopefully it will help a little for portrait orientations too. Landscape bespoke launch images should be placed as shown with these width/height class settings.
Use the launchImage.xcassets screenshot at the top of the question to set up your launchImage.xcassets.

Launch Screen that behaves exactly like Launch Image

In order to get iPad Pro to use full resolution at launch, we have to use a Launch Screen File.
I've never used a Launch Screen XIB/Storyboard before, because my app is backwards compatible to iOS 7. Normally I use a LaunchImage asset catalog to define a specific static image for each device dimension and launch orientation.
Now I'm trying to define a Launch Screen File that acts like a LaunchImage asset catalog, but I'm struggling to do it. In particular:
1) I don't see a good way to select a different UIImage depending on the exact size of the device, e.g. show one image to iPhone 4S users and another image to iPhone 5 users.
2) I don't see a way to select a different UIImage for iPad Portrait and iPad Landscape views. Size classes seem to think that both iPad Portrait and iPad Landscape are "Regular" width and "Regular" height, so any UIImage that would show up on iPad Portrait will also show up in iPad Landscape.
The system loads the launch file before launching the app which creates some constraints on what it can contain (some of which may force you back to static image files):
1.The app is not yet loaded so the view hierarchy does not exist and the system can not call any custom view controller setup code you may have in the app (e.g. viewDidLoad)
2.You can only use standard UIKit classes so you can use UIView or UIViewController but not a custom subclass. If you try to set a custom class you will get an Illegal Configuration error in Xcode.
3.The launch file can only use basic UIKit views such as UIImageView and UILabel. You cannot use a UIWebView.
4.If you are using a storyboard you can specify multiple view controllers but there are again some limitations. For example you can embed view controllers in a navigation or tab bar controller but more complex container classes such as UISplitViewController do not work (at least not yet).
5.Localizing the launch file does not currently seem to have any effect. The base localization is always used so you will probably want to avoid text on the launch screen.
6.You cannot specify different launch files for iPad and iPhone. This may be a problem if you have significantly different interfaces for those devices as there is only so much you can do with auto layout and size classes.
Note that if you are deploying to iOS 7 you will still need to include the static launch image files. You can include both a launch image file and static launch images. Devices such as the iPhone 6 running iOS 8 will use the launch image file whilst iOS 7 devices will fallback to the launch images.
First create all your images. Then, open up your asset catalog and right click -> App Icons & Launch Images -> New iOS Launch Image. This will create an file to drag all your files into. Do that. Name the asset "Launch."
Create a new launch screen storyboard with command-n. Choose iOS -> User Interface -> Launch Screen. Call the file "Launch Screen."
In your Launch Screen storyboard, select the view controller's view
[.
Find the UIImageView placeholder from the object library in the bottom corner of the right side ba, and drag it into the launch screen view.
Now, select the image view in the storyboard, and type in the name of the image from your asset catalog.
Control drag from the UIImageView to it's container view to set up auto layout constraints as follows :
Optional... if you want it to look nice in your storyboard, select the view and do option-cmd-= to update the frame of the UIImageView.
Go to your info.plist, and type the name of your storyboard ("Launch
Screen") for the key "Launch screen interface file base name"
Clean and run.
Hope that helps and that I didn't forget anything!
You can use Size Classes to specify different images for different screen sizes, but this not help you handle cases of iPhone 4S and iPhone 5 screens
A different approach is using spacer views that position the correct image in the visible area and move the other one off screen (see my original answer to a similar question here).
You can't provide different images for different screen sizes (iPhone 4, iPhone X, ...), but if you want different images for iPhone and iPad and different images for portrait and landscape this solution is for you.
I created an example project on github if you want to try it out.
It works on iPad and iPhone.
The important constraints are
PortraitSpacer.width ≤ 5 × view.width
PortraitSpacer.width ≤ 5 × view.height
LandscapeSpacer.width ≥ 5 × view.width
LandscapeSpacer.width ≥ 5 × view.height
PositionSpacer.width = 5 × view.width
where view.width and view.height are the main view's width and height.
The PortraitSpacer positions the portrait image at 5 × min(view.width, view.height),
the LandscapeSpacer positions the landscape image at 5 × max(view.width, view.height),
and the PositionSpacer has the same width as PortraitSpacer in portrait mode and the same width as LandscapeSpacer in landscape mode.
We multiply everything with 5 so the two images do not overlap. This works for all devices where the following is true
5 × min(view.width, view.height) + max(view.width, view.height) ≤ 5 × max(view.width, view.height)
In landscape mode this would mean
5 / 4 ≤ view.width / view.height
which is the case for all current devices: iPad has the lowest aspect ratio with 4:3 which is still greater than 5:4.
You can then of course configure images per device (iPhone, iPad) in the asset catalog.
This is a solution for iPad that can work,
for iPhone you can use size classes and I am not posting that solution here.
The solution is to break up your splash screen image into components and to use constraints to manipulate the image for Portrait vs Landscape.
Here is an example of how I did it.
Create a launch storyboard for iPad
UILaunchStoryboardName~ipad (UILaunchStoryboardName~iphone )
Take your landscape image in my case 2048x1536
I took the landscape image and cut it into three
Center 1536x1536
Left 256x1536
Right 256x1536
On the launch storyboard I created 3 image views with the following constraints
Center Piece:
Pin to Top and bottom,
center in superview,
maintain aspect ratio
Left & Right Piece:
0 Trailing/Leading to Center,
Align Top,
Equal Height
Then for the Mode of the view for the left and right I changed it from aspect fill to bottom right and bottom left (worked best for me)
I know this seems like overkill for something that should be simple. My reason for using the launch storyboard over launch images was to cut down on app size. I needed fewer launch images and I could use jpeg rather than png

LaunchScreen.xib single image for all devices?

I'm using the current Xcode and targeting iOS 8.
I'm wondering if it's okay if in my LaunchScreen.xib I put a single imageView that is constrained to all sides of the parent container. Within that image view will be my splash image called: splash.png;
Now here's the kicker, this splash.png will be hi-res and all devices (iPhone/iPad) will use this one image. Is this ok according to apple's guidelines? (note: it's okay with me) I don't mind if it stretches to fit). Also note my app's only in portrait.
Yes. It's fine, that's because they introduced this new feature (launchscreen.xib).
For deployment targets prior to iOS 8, you add a set of launch images to an asset
catalog for each of the possible screen sizes.
New projects are created with a launch screen file called
LaunchScreen.xib. Alternately, you can create a new launch screen file
using File > New, selecting the User Interface category, and choosing
a file type of Launch Screen. The launch screen uses size classes to
adapt to different screen sizes and orientations, see Adapt to Multiple iOS Screen Sizes and Orientations with Size Classes for more
information.
Reference : Create and Set the iOS Launch Images or Launch Screen File

Resources