Autolayout just not working for every screen size - xcode

My app is a game and the menus have many labels and buttons and I cannot get all of the different screen sizes(iPhone 4/5/6/6+) to look acceptable from the same set of constraints.
Is there a way that you use to synchronize all the views together to look the same on all different screen sizes?
The project is locked to only portrait so I don't need to consider rotation.

For Autolayout, you
Consider the screen sizes you want to support.
Which view/buttons/labels/imageview etc you want to remain fixed while in
different screen size.
Which view/buttons/labels/imageview etc can be scaled to fit the screen.
Now if by scaling the things you can fit on the screen then you are good to go. But if you still can't find way then you would probably need to you use scrollview and and add a UIView (let's call it content view) to it put your all stuff in it and constraint them vertically all the way from top to bottom.This video can help you if you want to use scrollview
https://www.youtube.com/watch?v=UnQsFlMGDsI

Related

Autolayout needed if only support one orientation?

Is Autolayout needed to setup for any subview, if my application only support one orientation (e.g., landscape right), applied for all UIViewControllers?
Yes, of course in the case of using animation I agree. But for the normal case, do I need AutoLayout?
Note: I am using XCode7, Swift, ios9
Understanding Auto Layout
Auto Layout dynamically calculates the size and position of all the
views in your view hierarchy, based on constraints placed on those
views. For example, you can constrain a button so that it is
horizontally centered with an Image view and so that the button’s top
edge always remains 8 points below the image’s bottom. If the image
view’s size or position changes, the button’s position automatically
adjusts to match.
This constraint-based approach to design allows you to build user
interfaces that dynamically respond to both internal and external
changes.
Unless you are making an app for one specific screen size, you will want to
use Auto Layout.
Use cases:
You want to support different size classes.
You want to support different screen sizes.
The content displayed by the app changes.
The app supports internationalization.
The app supports Dynamic Type (iOS).
Most of these changes can occur at runtime, and they require a dynamic
response from your app. Others, like support for different screen
sizes, represent the app adapting to different environments. Even
through the screen size won’t typically change at runtime, creating an
adaptive interface lets your app run equally well on an iPhone 4S, an
iPhone 6 Plus, or even an iPad. Auto Layout is also a key component
for supporting Slide Over and Split Views on the iPad.
Auto layout is not required at all. Even for multiple orientations.
However, If you don't use it, you'll have to manage placement for all the different sized devices yourself. So you might as well use it.

How to resize between 3.5" and 4" screens (dynamic constraints in autolayout?)

I have one view filling the screen with a background image. Other views (text fields) are in exact positions (the background image includes the text field background images). When I change from 3.5" screen to 4", the text fields don't change in the same way that the background resizes. The bg image simply resizes to fill the screen, but the text fields jump out of alignment.
Is there a way to have two sets of constraints, one for each screen size? or is there a way to have views resize proportionally to another view?
EDIT:
Is there a way to have two sets of constraints, one for each screen
size?
Yes, by adding constraints programatically and checking [[UIScreen mainScreen] bounds] to get the screen size.
or is there a way to have views resize proportionally to another view?
Yes, you could set this up in interface builder. But it will be hard to manage, I would manage the constraints manually in code since you are using a custom background image the textviews need to position exactly
You're going to struggle to get these things to line up properly with the text view backgrounds being part of the background image.
You should amend your image assets and use the background property of UITextField to have an actual background image, and remove the boxes from your main background image. The icons could be separate images as well.
Failing that, it would make more sense to have the image stretch underneath the text boxes rather than on top.
Your layout is doing what it should do based on your description, but the image isn't stretching in the right way. In your screenshots, username is always the same distance from the top, and the others are the same distance from the bottom, but that isn't how image stretching works. I don't know how you've set it up but it would make sense to have a single image the size of the 4 inch screen, which has the bottom cut off for 3.5 inch devices, and constrain everything from the top.

Cocoa Scrolling Image Menu

I want to make a menu with a wide image that scrolls horizontally (it's a continuous image). What technique could I use for this?
Thanks!
The standard way to do this is to create a NSScrollView and nest a NSImage in it. You could run into problems if your continuous image is too large, however. In that case you'd want to split it into multiple NSImages and arrange them next to each other in the NSScrollView.

cocoa mac osx grid display of images of different sizes

what i'm trying to do is displaying a set of images in a grid like fashion but with different sizes as for images in landscape or portrait position, this excludes using the NSCollectionView because the item prototype's size can only be set once...
i'd go and add subviews programmatically to a scrollView but this yet again when the window's size changes and the scrollView get a bigger width, there will be just blank spaces on the right side...
you can checkout the image below for a better understanding...
http://i.stack.imgur.com/NVJjP.png
thanks in advance you guys...
what i ended up doing was implementing a purely mathematic algorithm where i calculated the (x,y) position for every new added photo depending on the previously added photos and it did a pretty good job... the container holding the photos was embedded in a scrollView, needless to say that i had to calculate the height of this container as well.

how to translate and scale a NSImage?

I have built so far an application that allows the user to drag and drop images onto a NSImageView. However, I want to be able to move these images by simply clicking on any image and hold down the mouse button to move it's location.
How can I manipulate NSImageView to translate/scale after setting the images down? Is that possible? I've read about the NSAffineTransform, but it seems like that is moving the images before creating the image itself. I already have the images on the canvas, and simply want to click and hold the image and move it with my mouse. Please help anyone!
There are two sides to this.
NSImage is the model object, which you might want to display in different ways, save to disk/archive, etc. If you want to actually change the model (scaling, rotating, etc.), implying a permanent change, then you are going to probably want to look at NSAffineTransform, Quartz drawing, etc.
But you probably didn't mean that. Instead you probably are interested in NSImageView, which is a view object, displaying the contents of the NSImage model object using whatever display attributes are desired. If you only want to change how an image is displayed, not what the actual bytes in the image are, then you are going to manipulate the NSImageView at run-time. You can use NSAffineTransform here as well, but it's somewhat uncommon (and usually unnecessary).
The key thing to note that is the NSImageView inherits from NSView, so you have all its power at your disposal. Take a look at certain methods, such as:
-setFrameSize: - useful for changing the view size, and thus the image display scale
-setFrameOrigin: - useful for changing the view position, and thus the apparent image position
Note again that these have nothing to do with images per se, and apply to all Cocoa views. You may want to take a look at a book like Cocoa Programming for Mac OS X to get you past the basics. (You can then do more interesting things, like rotation, animation, etc.)

Resources