scrolling entire screen with UIScrollview and UICollectionView - swift

I am trying to build this view where I have a UI Image view with some labels below it. And then Below this I have a Collection view which has a few items. I am struggling to figure out how I could have this view such that the whole screen keeps scrolling up once i get to the collection view.
Right now, the image view and the labels below scroll, but then the collection view only scrolls within its constraints. What I want is the entire screen to scroll up so the collection view items fill the screen up. I have seen several other replies to similar questions but am unable to follow it.
Can someone help with what I am doing wrong here ?

For the best practice on mobile programming, you should not have a scrollable view in another scrollable view. If you do so, you will have the problem as you described that your child collection view starts to scroll while other elements like your imageview and labels stay there.
To achieve your point, you can simply use a collection view and have custom cells. Now your entire window has only one scrollable view so it looks better. Then you are basically have different cell types. On top you have a collection cell as image, then you have few collection cell as labels, and so on.

Related

Will a UICollectionViewCell be reused if the collection view is within a UIScrollView?

I appreciate that the answer to the title of this post may be "depends", but let me add some further info.
I am creating an app which contains a view similar to the profile page of Instagram. I have been struggling to come up with a way to best do this. My first attempts mainly used numerous collection views (including compositional layouts or flow layouts), however, although I got close, I was unable to come up with a solid solution using these methods.
My best attempt so far has been based on Swift Instagram's profile view with its exact behaviour and https://github.com/eduasinco/ProfileView, which I now have working to a satisfactory level. I recreated this programmatically and substituted out the table views for collection views, therefore there are some minor differences here and there.
My questions are:
Assume I have a collection view flow layout within a scroll view. The collection view height is set dynamically to the height of the content (i.e. number of items) and the collection view scrolling disabled. The height of the collection view is greater than the height of the scroll view, resulting in the vertical scroll behaviour coming from the outer scroll view;
Will all collection view cells be dequeued upon initial load - I have put break points in cellForItemAt for the collection view and upon scrolling the outer scroll view they are obviously not being hit?
Is this a problem performance-wise?
Is there a more preferred or "best practice" approach to take?

How create collectionview header like instagram tags searching one?

Can anyone help me how this header can be implemented? Especially how it works during scrolling? Seems that when I scroll to bottom this header is pushed up like a cell, but when I scroll to top it's static and looks like a view over collection view.
Photos
1) INITIAL STATE
2) SCROLL TO TOP
I believe the header isn't part of the collection view at all, but a sibling, i.e. the both share the same superview.
The collection view is given a large content inset at the top to make room for the header. Then, as the collection view scrolls, the scroll events are captured via delegate method and used to shrink or expand the header to make it appear as if it's sliding beneath the navBar.
(For reasons that have to do with the navBar translucency, it's not actually pushed under the navBar, but that's not immediately relevant to this question)

make view controller scrollable with collection view

I need to create a view controller like this or like user instagram's profile
not exactly same, I just want to add label and buttons and collection view,
but I want all of this in scroll viewController
I think I can't do that from storyboard, so how I can make a view controller scrollable programmatically?
and then I want to add the label and buttons inside the scroll , I can do that programmatically , but how I can add collection programmatically inside it?
One of the possible solutions is to make the whole container a "UICollectionView" -or "UITableView", depends on what exactly you want to build-, and then, create a custom cell for each area depending on what do you want to display in it.
It might sounds a little bit strange in the beginning, but you will notice that it is a great technique to handle scrolling in your scene, including some of extra nice features, such as:
auto scroll content resizing for "UIKeyboardWillShowNotification" and "UIKeyboardWillHideNotification" events.
the ease of showing and hiding sections from the UI (actually they are cells!).
UPDATED: For example:
You can make the first part (red rectangle) as a UICollectionReusableView and customize it by adding your images and button in it, second part (blue square) as a UICollectionViewCell and so on...
This is the general idea of what how you can do it.

How would I reload custom views in a scroll view?

I have a scroll view that loads custom views (using a nib) from CoreData. They appear in a x by 2 grid that scrolls vertically. The problem I face is reloading the scroll view when I add or delete an item. I have tried redrawing the views once my data has been updated, but right now my solution is re-instantiating the view controller that holds my data from the very beginning of the navigation stack, thus redrawing the views as I need. The problem with this is that it creates extra views (UINavigationView) in the hierarchy, which is not a desired behavior.
How would I achieve the same result without creating extra views in the hierarchy?
This is my ViewController
Judging from your image, I would suggest abandoning your entire architecture and just using a UICollectionView. The three red rectangles would then be UICollectionViewCells. UICollectionView does a wonderful automatic job of dealing with insertion or deletion of a cell; indeed, it even animates the change.

iPhone: How to Place a Scrollview Inside of Tableview Cell

I want to put a scroll view inside of the table view cell. I have a number of buttons in one cell of table view and I need to scroll that cell to show the appropriate button.
If you want to use a vertical scroll view then I wouldn't suggest you doing it because, as TechZen wrote, there will be a mess in this case.
If you want the inner scroll view to scroll horizontally then it might be achieved by 2 ways:
Implement a custom table view cell that will include a scroll view inside it.
Add a scroll view as a sub-view to your cell that you will return from tableView:cellForRowAtIndexPath: method.
I suggest you to use the second approach.
There are plenty of examples online. Usually the sub-views are labels or image views, but it is not complicated at all to add a scroll view instead...
I don't think you can do this. It would require nesting of scrollviews which isn't really supported.
Even if it was, it would be very difficult for a user to know which scrollview they were hitting with their pudgy finger. Remember, you don't have the one pixel precision of a mouse on the iPhone. You have an area of at least 15x15 pixels. You don't have a scroll bar but instead just drags anywhere on the screen.
Instead, you should use a master-detail pattern. Selecting the cell in the tableview pushes a detail view which has the scroll view with all the buttons.
Why do you want to do it like this?
I think the best idea is to draw your table view manually above your uiscrollview. I did it, and it works. It just takes more effort and drawing accuracy. But that takes a lot of time. :)