Is Constraints necessary for tvos app? - ios

I am new to Apple TV apps development. I have designed few views on storyboard, which is looking nice on Apple TV simulator, but some control's edges are cutting when I am running it on HDMI monitor and actual tv.
I want to know, if constraints are needed to manage UI for different sizes of Tvs? If no, is there any standard Apple has introduced to manage this part?

Using Autolayout is recommended, but not required. However, it's a good chance this isn't your issue. If you're developing a tvOS app, be aware that there is a safe area you need to work with. Many TV's (including some new HDTV's) will cut the edges of the screen off (this is called overscan). The safe area is the part of the screen in the centre that you should ensure all of your important content is in.
So, for a tvOS app, you should set up your views with the dimensions of 1920x1080, but keep all of your important content, buttons, text etc, inside the centre 1740x960 region. This leaves 90px borders on the sides, and 60px borders on the top and bottom. Those borders should of course still have non-important information, such as your background images etc.
See here for more details: https://developer.apple.com/tvos/human-interface-guidelines/visual-design/#layout

Constraints are not mandatory, but they can save you a lot of trouble. Furthermore, actually constraints(auto layout) are how Apple wants developers to manage the app for different resolutions.
Take a look at: https://developer.apple.com/library/tvos/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html
If you are new to constraints, I also found this tutorial helpful: http://code.tutsplus.com/tutorials/an-introduction-to-tvos-development--cms-24848

Autolayout is not mandatory for any kind of development whether is ios, tvos or watchos. we have option in file inspector to disable autolayout that means it is not necessary. But if you use autolayout it can make your task too much easy.
Not using autolayout does make the assumption that your app will never run at any other resolution, but more importantly, autolayout is very helpful when it comes down to dealing with things other than overall screen size, such as localization of text and buttons etc.
If you use autolayout then it can help you in future release of tvos of different screensize.
Hope this will help :)

Related

Auto-layout not regular across different screen size

I am new to iOS platform but still been able to build my first app in the last 3 weeks. Coming from android, I was able to leverage of some of the knowledge I had to adapt quickly to swift and iOS but I struggle with auto-layout in the storyboard. I have not been able to get a flow that works.
I am currently using Xcode 11 and have tried to UIScrollView but to no uniformity. Whatever I arrange correctly on iPhone 11 deforms on iPhone 8 or lower.
I have watched different tutorials on youtube, lynda.com and pluralsight but to no avail.
What is the best possible way to use auto-layout across different screens like we have in android with constraint layout/relative layout?
I recommend using anchor constrains programmatically. Setting border relative to different items will provide autolayout in all devices. If you post a screenshot of your needs , it might be easier to provide accurate answer. Also keep in mind that superview borders in iphone 8 and lower version differ from borders in higher version according to the top notches. You need to set your views relative to safe area of the superview.

How do you build apps for all iOS devices?

I have an app that is nearing completion. However, I don't know how to finish it so it will look good on all iOS devices. It's a portrait only app, and it is the same on all devices (bigger screens don't show anything extra or different from smaller devices).
How do I make constraints that will work on all devices? I know there are different size classes that Xcode has, but it seems tedious to go to each class and add specific constraints.
You should use Autolayout for all resizing of your UI. But if you still want to go with this, I found this thread What setting determines whether an app gets scaled for iPhone 6 and 6plus?
Again, try to use Autolayout, add constraints its very easy. If you wish to change your mind go through the tutorial and add constraints https://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2

Manually adjusting positions of UI elements in Xcode's storyboard

Instead of having to use xcodes constraints, which I can never get to work right, is there a way to manually set where UI elements are on the screen? I noticed that if I'm on the attributes bar for the view controller, I can set simulated metrics's size to any iphone size I want.
Then I can position the UI elements on the screen where I please. When I build and run, it always mimics exactly what I set up. However, it only works for the particular size of the iphone I specified. Is there a way to do all the sizes manually without making several xcode projects?
Thanks!
There is multiple other solution that is not as good as constraints.
1) Use frame property of views to place them
2) Use size classes to do different placement for iPad iPhone etc
3) Use suggested constraints - you are placing views and than you can give XCode possibility to create constraints for you suggesting what you want from your views placement.
You're going to want to learn how to properly use constraints. The approach you're trying to do would have been okay when there was only one screen size, but now we have three different sizes of iPad, two watch sizes and four different iPhone sizes. Here's a link to a tutorial from Ray Wenderlich (he has some pretty good tutorials to get you started n a wide variety of things). https://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2
The auto layout in storyboard on Xcode 7 isn't my favorite, but when Xcode 8 comes out it provides device specific sizes for views that makes auto layout much easier. So maybe Xcode 8 will provide a better solution to your problem!

Updating controller from iPhone to iPad with size classes?

I have been using autolayout and constraints to make my app look pretty on every iPhone, and it looks ok so far. I am having problem with iPad. I have a screen that when viewed on iPad has to much blank space.
I would like to use bigger images, and larger font. Maybe add one more label. Can I do this with sizeclasses, or i have to do it some other way?
Yes, you can do all that with size classes – and indeed they are the preferred solution for this, because you automatically get support for slide over and split view.
If you're using Interface Builder (which, quite frankly, is by far the best way to work with size classes), you'll see little + buttons next to many configuration option of your user interface. For example, you mentioned larger font: right there to the left of the font options is a + symbol, and clicking it lets you add a different font size for specific size classes.
I made an app a few months ago that worked on all iPhones and iPads as well as Apple TV, all using the same base storyboard with customisations using size classes. There's such a big gap between the tiny iPhone 4s and the massive iPad Pro that size classes were basically essential. And yes, split view worked flawlessly out of the box, which was a bonus.
My primary advice: Design for your smallest screen first, then add size classes to configure the largest options. You can then choose some views to either not be installed (it's a checkbox) or just be sized down very small to make sure your UI looks and works great in its most challenging environment. If you can do that, making iPad work is a cinch because it feels like you have acres of space ;)
Another useful tip that enough people know about: Enable the assistant editor, then choose Preview mode for your storyboard. This lets you see how your layouts look on multiple different devices and orientations simultaneously, as you work. If you're looking to make best use of size classes (and the massive difference in space between iPhone and iPad) using the previewer is essential.

Auto layout or Autoresizing

I'm starting to develop an app that will only be on iPhone and only portrait view. I'm wondering the best way to develop an interface for both iPhone 3.5 inch and 4 inch screen. Every tutorial i see for auto layout seems to use it for portrait to landscape, but for me that doesn't matter because landscape isn't an option. I'm just wondering if I'm only using portrait is it easier to go with auto resizing?
Edit: I'll be using some UI animations in the project as well.
That depends on how your view sizes and positions relate to each other. If you want to align various views, or have views move when the text in a button or label moves then auto-layout is your friend. If you just want to resize a scroll view to fill the available space then auto-resizing is much simpler.
Arguably, learning auto-layout on a relatively simple app is a wise move to support your future app building endeavours...
If you want to make a relation between subviews and superview go for auto-resizing.
Otherwise if you want to make the relation between view or their neighbors view or adjacent view then go for auto layouts.
Auto Layout, because new features and functionality will be designed to work with Auto Layout, and your app will be more likely to be laid out correctly on upcoming devices or operating systems.
A case in point for iOS 8 is Adaptive UI. Apple has figured out and handled most of the edge cases, and content adapts to its view controller being collapsed or separated, remaining properly sized regardless of the device orientation or size. One code base. No conditional code required.
When Apple comes out with a new device or operating system, it's more likely that your app will behave more robustly if you use Auto Layout. If you size things yourself, you may overlook an edge case or not be prepared for a new size class, and your layout might break.
It comes down to how much code you want to write, support, and upgrade, versus letting the SDK figure out sizing, positioning, and relationships for you. Does their code have bugs? Yes. Does our code have bugs? Yes. Either way, it's not a perfect world. But anyone who adopted Auto Layout earlier, got a lot of functionality for free later. I believe adopting Auto Layout and size classes will continue to pay off, even at this stage.

Resources