Saturday, November 29, 2014

The new UISplitViewController, Swift and iOS 7

I was playing around with Swift today and stumbled upon the new awesome UISplitViewController in iOS 8. This enhanced version of the controller makes it work for all iOS devices (originally, it only works with iPads). With the introduction of the "phablet", Apple had to improved their SDK to make it easier for devs to build app that works across all screen sizes. That's a good thing, but a little too late IMHO.

Anyway, back to UISplitViewController, the app created by the Xcode template only works with iOS 8 so I tried to dig in and see if it is possible to support iOS 7 with the same code, same storyboard and everything. It looked like it was possible. Many people tried that, particularly this blog post, but the best solution out there still doesn't have it working smoothly in iPad portrait mode where it should show a button to open the master view in a popup... After a few hours looking around, I finally found the solution and have a demo project available at github.com. Check it out now and I hope you find it useful.

Below are some screenshots:

UISplitViewController in iPad/iOS 7: button with text
UISplitViewController in iPad/iOS 8: button with text + arrow

UISplitViewController in iPhone 5s/iOS 7: button with text + arrow
UISplitViewController in iPhone 5s/iOS 8: button with text + arrow



UISplitViewController in iPhone 6+ landscape: fullscreen button

Download demo project here.