UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Best approach to target two different devices

Forums > iOS

I'm working on an app where the main target audience are iPad users. IPad should only support landscape mode. Secondary, I do not want to leave iPhone users out, so I would also like to support iPhones in portrait modes.

First screen of the app is a CollectionView, with two sections. I got that up and running with diffable datasource and compositional layout. However, I am having a hard time to get it to look good on both supported devices / orientations. I think I need to do some device specifc things.

More so, the app will have a master-detail (SplitViewController) screen, which behaves differently on iPhone and iPad. Whole UI will be done programmatically using UIKit!

I wonder what the best approach would be. I could check for screensizes and have the layout change based upon those conditions, but that seems rather messy? Or would it be best to use a coordinator pattern and present different versions of the screens, depending on device. I have very limited experience with coordinator pattern, did 2 of Paul's example projects, but this might be the route worth taking ...

Opinions?

4      

@mecid  

Hello, UITraitCollection is all you need. You can use it to check the width of your device, it can be regular for iPad and compact for iPhone.

UISplitViewController is also an awesome way to configure master-details flow for iPhone and iPad.

4      

Thanks! I'm totally blank concearning UITraitCollection, so I guess I'll be diving into that! Sounds promising!

EDIT

Nice, works great, got it working now. Now to find out how to limit the app to only portrait on iPhones and only landscape on iPads :smile:

3      

Regarding UITraitCollection... Any clue why iPhoneX in portrait mode regularXcompact, but in landscape mode it's compactXcompact? It doesn't look logical. What is the criteria for defining these size classes?

3      

Not sure if it answers your question, but I found this article on the topic very helpful: https://medium.com/if-let-swift-programming/size-classes-ipad-portrait-landscape-55f59173c65a

HTH 👍

4      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.