Possible with launch storyboard? - ios

The height of the upper toolbar of my photo app varies from one screen size to another...
On 4" screens, the height is 40 points
On 4.7" and 5.5", it's 30% of the screen height
On other screens, it's 77 points
Considering those specifications, would it be possible to use a launch storyboard?

In a Launch Screen storyboard you can use variations that are based on size classes. Unfortunately in your case that does not work because in portrait mode all iOS Devices share the same height size class (Regular). So size classes are of no help here.
If the Launch Screen would be a "normal" UIViewController you could update the height constraint of your upper toolbar programmatically. This does not work for a Launch Screen because it is displayed before you app is even running. You cannot change anything programmatically in a Launch Screen. So this does not work either.
What you could do is to set different Launch Images (depending on screen size) using your app's asset catalogue:
Select your Asset catalogue in the Project navigator.
Press the "+" and select "App Icons & LaunchImages" → "New iOS Launch Image"
Now you can add different Launch Images for different Devices:
I'm afraid this is the only way that you can address the different devices screen sizes.

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 Storyboard

As LaunchScreen I want to have an exact image of the start page that appears right after the launch.
Therefore, I made screenshots of all resolutions of the start page, both portrait and landscape. Then I removed all fonts because I generate two variants of the app in different languages and the texts (e.g. in the buttons) are different. The launch screens should fit both variants.
In Images.xcassets I added LaunchImage and assigned all positions with the correct resolutions (for both, iPhone and iPad).
LaunchScreen.storyboard has an ImageView in the ViewController with the image name LaunchImage.
Result:
1 All launch images displayed are scaled even though the correct resolutions are available.
Only the portrait images are used, also for landscape, and therefore scaled and distorted.
on iPads only iPhone images are displayed, portrait version also in landscape, scaled accordingly.
On some devices (e.g. iPhone X), only a white or black screen is displayed at launch (portrait and landscape).
Under no circumstances will the correct launch screen be displayed.
On the image you see all relevant areas and the list of all used launch images.
What did I do wrong or miss?
Supplement:
I just followed another tip and deactivated "Clears Graphic Context" in UIImageView and changed the display to "Aspect Fit".
Result: The portrait launch image is still used in the iPad, but is no longer scaled and is now centered.
So the most important question now is why an iPhone portrait launch image is used for iPad in both directions.
If you are using a LaunchImage, you should set that image in the Target settings. Go to your target and under the General tab, set the Launch Images Source value to the image you have in your asset catalog:
Also delete the text LaunchScreen in the Launch Screen File field.

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

Launch screen.storyboard for Portrait and Landscape vs split screen

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.

Resources