xcode, align 20 images, grid view - ios

Need some help ^_^,
I'm trying to align 20 images together, in the storyboard,
https://www.dropbox.com/s/cnyojn82rn84c9j/pic1.jpg?dl=0
https://www.dropbox.com/s/05u50dd54w756q7/pic2.jpg?dl=0
I need them to look same in the portrait and landscape mode, so if you imagine rotating phone, then 20 pictures rotate 90 degrees, but not the whole view, when view rotates to landscape, bottom row disappears.
Sorry, it's hard to explain =D, basically in portrait top row has 4 pictures, in landscape top row should have 5 pictures.
Would be even better if they would change size of the image depending on the screen size.
Thanks,

Why there is need of 20 images to be designed in storyboard, When we have UICollectionView for that purpose, you never need to worry about the rotation, Collection view will automatically adjust it cells accordingly.
If you need tutorial you can surely go ahead with this link

I suggest you look into UICollection views with a flow layout. It might sound unwieldy at first but it is definitely the best solution for what you want to achieve. Apple documentation can be found here: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CollectionViewPGforIOS.pdf

Related

UICollectionView Full Screen Vertically and 2 Screens Horizontally

I have a UICollectionView that displays one cell at a time that has the size equals to the UIViewController.view.bounds.size. This works great for me on Vertical/Portrait screen.
I want to rotate the screen to landscape and a nice animation happens to show 2 cells side by side each having size equals to CGSize(UIViewController.view.bounds.width / 2, UIViewController.view.bounds.height)
Is there a library that does that or how can I achieve this approach?
You can think of it as an image gallery that displays one image at a time when rotated should show 2 images.
If you are using flow layout, then all you have to do is implement UICollectionViewFlowLayout delegate methods, and invalidate the collectionView's layout on rotation.
Take a look at this repo: dynamic width cells
It's not exactly what you are looking for, but you can get a general idea.

Using AutoLayout to just rotate a View

With AutoLayout, is it possible to keep a View (button, image, etc) in the same location but just rotate it 90 degrees when the device is rotated?
For example, in the following images the Views stay exactly as they were placed in the portrait orientation (same distances from the edges), but are rotated in landscape.
You describe the views in the images you've provided as "staying in exactly the same place", but I think this is to misunderstand autolayout and the rotation behaviour. Your layout has changed significantly between the two examples. Where both views were previously aligned along their left edges, now they're aligned along their bottom edges.
Basically: when you rotate the device (lets say from standard portrait to home-left-landscape) you're changing which view is the top, not the direction the top view is pointing.
If you want to recreate the look of the rotated view you provided, you have a few options. I'd suggest looking at the visual formatting language, which is a good way of adding constraints programatically... it's easier then it seems. Take a look at the iOS auto-layout talks from WWDC 2012 if you want a good introduction. You could then add and remove the appropriate constraints when the device rotates. (it might take a bit of playing around). There's also a section in the View Controller Programming Guide on 'creating a custom landscape orientation' that might be helpful.
If you're allowing the interface orientation to rotate, then you'll have to change your constraints on rotation to put the views where you want them.
If you're not allowing the interface orientation to rotate, then you'll have to subscribe to device orientation change notifications. When the orientation changes, you can update the transforms of the views to rotate them. If the views are square, that should suffice. If the views are not square, you also need to modify your constraints based on the rotated frames.

Manipulating scroll view in Corona SDK

I have a class with a scroll view that has a width of 980. I also have about 100 buttons aligned 5 columns x 5 rows for each 320 width of my scroll view. The scroll works okay but I'm trying to achieve two things:
Allow scrolling only when slide length is about 50% of screen size
If the slide length is half the screen size, then it would immediately slide/scroll to the next 25 items. For example, in plain sight you would see buttons 1-25 then if you try to scroll, the next 25 objects would be displayed (buttons 26-50).
I followed the sample from here but I don't know how to implement what I want to do or if it's even possible to do this using scroll view. I hope someone can give me a good example or idea. Thanks.
Try something like this: http://developer.coronalabs.com/code/slider-module-springboard-functionality-warning-shameless-promotion-inside. It works sort of like the iOS springboard.

UIPageViewController rotation weirdness

I've added a UIPageViewController to my app to act as a manual for the app. When the user pops it up it shows one page in portrait and two in landscape with the spine in the middle. Since I have about 100 pages, there is a sibling view UICollectionView page selector view above it to allow jumping to a page quickly. Both the UIPageViewController and the UICollectionView sit on a backing view that contains them both.
The problem I am having with the UIPageViewController is that when the views are first rotated they seem to constrain themselves to the short dimension of the original layout. So, if it first appears in portrait, then when rotating to landscape the width of the two pages is the same as the old portrait width. Likewise, if it first appears landscape with two pages, rotating to portrait has the correct width, but the height is the height of the initial landscape height. This is consistent on any device.
When I create my content views they are all the size I desire, but for some reason they seem to be transformed by some component of UIPageViewController and I'm not grasping why it is only doing one of the two dimensions and why it is always the "short side" that is the problem.
This is one of those kinds of problem that makes me feel a bit nutty, any ideas on how I might debug it if it isn't some trivial misconfiguration?
I finally found it after a long period of debugging. The critical hint was seeing that the spine is set to the correct mid for the width of the view BEFORE the rotation for portrait to landscape. The solution was to reset the frame of the view to the new size given the orientation in willAnimateRotationToInterfaceOrientation.
I calculate the new size before I call an animation block that uses the duration passed into the method, then inside the block I have:
pageViewController.view.frame = newFrame;
When the page is rotated the view holding the content pages is shifted to the correct size and the spine is place correctly and the content fills the given area. I suppose that I ran into the problem because the complexity of the views required me to take over so many defaults, but this one was left hanging.

Auto resizing UITableView on rotation with flexible width

I am adding UIButtons to a UIView located on the right side of a split view controller. Without any autoresizing set, the button text fully displays in landscape orientation. When I rotate to portrait orientation, all button text is fully displayed, but there is extra space on the right hand side of the UIView, because there is more real estate to work with.
I would like these buttons to resize on rotation so that it utilizes the entire width. I tried setting:
[button setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
With this in place, the same extra real estate exists on the portrait orientation, but in landscape orientation I get a lot of buttons with the text shortened with "..."
How can this be done?
when the AutoResisingMask doesnt do it for me, I always resort to subclassing the UIView and overriding the layoutSubviews... this way I can manually place those tricky views that never look right in different orientations.
in fact.. at last year's WWDC, I heard an Apple Engineer say that he "always" creates and adds his views with frame CGRectZero, then sets the correct frame in layoutSubviews. For what its worth...

Resources