UICollectionView screen-sized cell rotation? - ios

Imagine a composition like this ->
UIViewController with root view containing these subviews :
- header view pinned to top,
- footer view pinned to bottom,
- scrollview matching the screen bounds with uiimageview as content where the image of the image view is a landscape image and the imageview size is aspect fitting the scrollview, zommscale is 1.
If I rotate this controller, thanks to proper layout(doesnt matter if manual or autolayout) the resulting animation to new landscape screen bounds is flawless.
If I put this controller as a member of UIPageViewController multiple times (effectively creating a gallery) the rotation of any particular page, containing a controller from above is also flawless.
In both cases above, none of the layers dissapear, the resizing animation nicely comforms to layout rules. The animation as a whole makes complete sense.
Now let's create a Collection controller with a horizontal flow layout. Zero insets, zero interitem size, and the cell size matching one screen. We ended up with horizontal gallery right?
So why, when I rotate the device, is the final animation composition so messy?
I slowed down the animation and what I see is views from neighbouring controllers temporarily "leaking in"
the central image view is deformed while animated and eventually thrown away, and finaly it calms down and a new! cell content is shown with proper layout that comforms the landscape device orientation. It's like those views are not sure what they want and behave like drunk.
Why cant the collection view rotate in such a way that only the cell will resize alongside the animation coordinator and firmly keep it's center in the center of screen?
How to force collection view to resize it's current and only visible cell in same manner as if it was a root view?

Related

Content in UIScrollView is being cutoff early

I have several UIViews within aUIScrollView and I want them to scroll all the way to the bottom of the UIScrollView before cutting off (See Image #2).
Background on the scroll view:
I created the UIScrollView itself is a subclass of a customUIView. I put the view in a UIScrollView so the auto layout in storyboard creates the correct frame for the device.
In the view controller attached to the storyboard UIViewController I created anIBOutlet to theUIView, and in the viewDidAppear function I called a function attached to the view that populated the UIScrollView.
In the storyboard I gave the view a blue background so I could tell its frame. Here is the what the storyboard looks like:
Then this is what it looks like on my phone:
Notice how much space exists between where the view cuts off and where the bottom of the screen is. It does this on all devices.
I have tried adjusting the bottom content inset. It is currently at 0.0 but I tried to make it -20 and that did not help.
How can I fix this?

UICollectionView with subviews only redraws when reappearing

I'm currently building an app that uses a collection view showing images, among other stuff, inside cells.
The controller dequeues a cell, sets an image, and calls a method to change the frame of the image.
I change the image position and size like so:
[imageView setFrame:CGRectMake(imageViewXOrigin,
imageViewYOrigin,
imageViewWidth,
imageViewHeight)];
This is after calculating all 4 values.
After that, the controller returns the cell, and it gets drawn on screen.
The problem is that it's drawn using the old dimensions, and only after scrolling the cell out of the screen and scrolling it back in again will it display correctly. How do I fix this?
Using a standard storyboard mode is out of the question, because I want the image to be an aspect fit bottom left, which can't be accomplished by using the storyboard.
How do I fix this?

ScrollView inside View or Vice Versa?

I am working in iOS and cannot find if there is a definitive answer to this.
I have a screen, the entire thing will scroll (not just part of it is scrolling at the top). I am using Storyboards to build this and the content is bigger than the screen size. Is the best way to do this with:
This is all inside of a UIViewController.
The content inside a View (child) inside a fullscreen ScrollView (parent) and set content size of ScrollView as the View's frame.
The content inside a ScrollView (child) inside a fullscreen View (parent) and set content size of ScrollView as its frame and then its new frame as the View's frame.
Just a ScrollView as the first child of the ViewController and set its content size as its frame and then its frame as the screen size (which I would need to check at runtime?)
All of these methods seem to work, but they make other things easier/harder (moving content for keyboard, etc.). Is it simply a matter of opinion or is there a "best/correct" method?
You have to set content size bigger than your view. Then It will scroll.

UIScrollview, other controls, not scrolling

I have an app which shows two images housed within a UIScrollview.
The scrollview is of size (320, 530), underneath it is an imageview size (320,38), this acts like a dock at the bottom of this screen, ( in fact it has to be there at the bottom of all screens in this app).
As it stand the scrollview works fine and the images switch from one to anothr when the user
moves the scrollview.
The problem is, I need the scrollview height to go all the way down ( from 530 to 568), and end up behind the dock imageview, when I change its height and the height of images within it, it just stops scrolling.
Is this impossible in scrollviews? does it have to have all of its screen real estate as top view?
Any solutions for this?
Thanks.
Update :
so I worked on the alpha and the image constraints, and the bottom imnage is located properly,
still the scrolling is not functioning.this is the latest code with changes.
http://ge.tt/4LYJGWl/v/0?c
thanks.
This is certainly possible. Add a full height scroll view to the controller's view, then add the small image view to the bottom. In the scene list at the left move that image view up so it's directly underneath the main view, which will make it a subview of that view rather than the scroll view (you'll then need to move the scroll view up above the image view so the image view will appear on top). You'll probably have to change some constraints to pin it to the bottom, and give it an alpha value less than 1 so the scroll view will show through.
After Edit
This is the screen shot of the scene from your updated code:
You only have one view that's directly under the main view, your scroll view. Compare that to my image.

How can I place a non-scrolling UIView underneath the scroll indicators on a UIScrollView?

I have an application where I'm using a zooming scrollView to do image cropping to a rectangle with a fixed aspect ratio. I have a mask where I darken the parts of the image that will be cropped. Currently I add this subview to the UIScrollView's parent, making them siblings, where this mask is 'higher' than the scrollview. Looks great. Except...
This mask is also masking the scrollIndicators and therefore looks a bit dumb. I could turn off the scrollIndicators, or, ideally, I'd like to place this UIView underneath the scrollIndicators, but not get scrolled with other content, which is what would happen if I made it a subview of the scrollview via [scrollView addSubview: myMaskView];
Anyone know if this is possible?
First, subclass UIScrollView so that you can modify the default behavior of scroll view.
Second create an image view with your image, and put both the image view and your mask view to a scroll view, this way your views will be underneath the scroll indicator.
Third, in your scroll view delegate method viewForZoomingInScrollView:, return your image view, so that only the image view zooms. Note that the scroll view will adjust the content size to be the size of the returned view, but it's fine as long as your image view takes up the whole content size.
And last, override layoutSubviews method, move the mask view to visible bounds of scroll view. The layoutSubviews method is said to be called every frame of scrolling, so the position change won't be visible to end user.
For more details you can refer WWDC session video "Advanced ScrollView Techniques".
EDIT: OK, just found that you can avoid overriding layoutSubviews by implementing the delegate method scrollViewDidScroll.

Resources