UICollectionView with subviews only redraws when reappearing - ios

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?

Related

Stop UICollectionView hiding cells out of view bounds

I have a horizontal-scrolling UICollectionView which is nested in a UIView that is centred and occupies 80% of the screen width.
I want the UICollectionView to be visible screen edge-to-edge rather than constrained to the super UIView bounds.
I have set the following which shows the UICollectionView across the screen width:
collectionView.clipToBounds = NO
...but when dragging the collectionView, it hides cells when they are completely outside of the super UIView bounds even though they are partially visible on the screen, which leads to a weird flickering of blank space/cell.
Ideally, I'd like a way to prevent the hiding of the cells completely out of bounds. Is there a way to do this?
The UICollectionView has a maximum size of 3 cells, so I'm not particularly worried about any performance implications of having all cells visible all the time.
The only way I found is to enlarge the frame of the collection view (and its superview in your case) and add contentInset's to it. You might also want to update scrollIndicatorInsets.

Custom tableview scroll iOS

I need to show three/ four UI buttons and levels, two image views in a custom cell but there is a condition on the basis of that I need to hide an imageView and when it will be hidden, I need to decrease tableview size and buttons which are below of that image view that will move upward.
For that I am giving required conditions in
heightForRowAtIndexPath
and returning cells height accordingly and in tableview
CellForRowAtIndexPath
method I am hiding imageView and setting buttons positions which are below of that imageView.
The problem is that:
1) TableView is not scrolling smoothly
2) Initially at the time of scrolling down everything is working but when I
move upward then image is resizing and changing its shape. To solve that I have used AutoLayout but still it is not working.
I need your expert advice.
Thanks in advance.

Infinity backgroundView in tableView

I have UITableView with background image and then I scroll it I have parallax effect like background imageView scrolls too. Problem is that then my image finished I have tableView background. Is it possible to make infinity imageView? Like then I go through image then starts this one image from beginning.
In next few days I will add lib thay solved it and creates parallax effect under tableView
https://github.com/bizibizi/TableView-Parallax-Background
Can you show me how are you placing that image behind the TableView? I guess the hierarchy in the storyboard should be
UIView -> UIImageView -> UITableView
The size of the UIImageView and the UITableView should be the same. So when you scroll up and down the UITableViewyou could see the image in the background.
But please explain your scenario abit more so that I could suggest you something appropriate.
What Hanny means is that you need to have the tableView on top of imageView ordered in the stack of the parent view's subviews. What you can also do is stack two tableviews on top of each other, and add a touch event that moves both table view's scroll views. The image table view would contain cells that are the size of the whole view frame.

UICollectionView with custom UICollectionViewLayOut

I am trying to have the content in a uicollectionviewcell grow bigger when it scroll moving in one direction. i initially set the size of the cell to the largest size i want, then the content inside the cell is half in terms of the size. the content is an uiimageview.
So I have a custom UICollectionViewFlowLayout in which I subclassed the layoutAttributesForElementsInRect to make the uiimageview in the cells grow bigger when it is moving in one direction. i also have shouldInvalidateLayoutForBoundsChange to return YES
Everything works perfectly when i scroll, the imageview will grow larger. However if i select a cell to push to a new viewcontroller, and then when i click the back button to come back to this uicolletionview, the enlarged uiimageview in severals cells are showing in the original size. They can only go back to the correct enlarged size if i scroll again, why is that? and how can i make it keep its enlarged size after getting pushed?
i tried invalidatelayout but it will just refresh the layoutattributes with correct enlarged size of the content, but the view is just not updated eventhough the size is already enlarged.
thanks
I had a similar issue when designing cv cells and would gess the issue is with when the subviews get calls to update their size, which might not happen when the view refreshes.
Instead of resizing content in the cell, you might want to dynamically size the cells themselves and have the content automatically adjust to that size. Calling [mycollection invalidateLayout] then should be all you need, maybe not even that.
The method is
collectionView:layout:sizeForItemAtIndexPath:
which you declare in your UICollectionViewFlowLayout.h
If you then run into trouble where subviews do not resize with cell size, related problems can arise from constraints/autolayout etc of the subviews.

Interface design in Foodspotting

On the app Foodspotting, you have a scrolling view that has two elements:
1) An image.
2) Some information below it.
Like this:
When you start scrolling down, the behaviour is not natural of a UITableView, or at least I am not understanding it. The below view start's going up and overlapping the UIImageView above it:
And finally:
What I have tried:
1) Using the first four cells without content and invisible and finally an UIImageView as subView of the UITableView
2) The same as above but using the UIImageView as subView of the root view and below the UITableView.
3) Mixing the UITableView and a UIScrollView with an UIImageView inside the UIScrollView.
So my question, how was this achieved?
Edit 1.0
If someone want to try, you can check the project here.
Looks to me like a UIViewController with a UIImageView on the bottom.
Then a UITableView on top of that (grouped table view) with a transparent background.
The header height is then set to almost the height of the entire view. With a button (or whatever that is) near the bottom of the header.
You could access the scrollView:didScroll to adjust the position of the UIImageView in the background (it looks like the center point of the image is always half way down the visible part of the header.
bgImageView.center = CGPointMake(0, (bgImageView.frame.size.height - scrollView.offset.y) * 0.5);
or something like that.
Obviously the image view would not move any further down than the top so you'd have to catch that somehow.
Looks like an image view is the background view of the table (so it won't scroll), a large transparent view as the table header (possibly with that first button in it, or that could be a transparent cell) then opaque cells for the remaining content.
And that risotto is far too wet. 0 stars, more like rice soup.

Resources