How to move a subview to front and have existing view shift up to make room? - swift

I have a collectionview that takes up the whole screen. Once the user clicks a cell and does stuff in the detail view, they are sent back to the first collectionview screen. At this point, I am bringing a view to the front that is a pseudo-tabbar. I want to shift the collection view up to accommodate this new view. Right now, it is just blocking the bottom row of collectionview cells. Thanks in advance!

Put the pseudo-tab bar in the initial view and constrain your collection view's bottom to the top of the tab bar.
Set the tab bar's initial height to 0. Don't just set it to hidden, because that keeps the view's original height.
When the user returns to the collection view, set the tab bar's height to the desired value. Animating it in will look even better.

Related

Smooth Scrolling between Table/Collection View and the Scroll View

I am implementing a scroll view which consists of an image underneath it is a collection view.
What I want to do is a smooth scrolling between the page as if the collection view is just elements in the scroll view.
But what happens is the when I scroll, the collection view needs to be dragged twice to exit it or to enter it.
What I mean is that when the scroll view first appears there is an image and under it is collection view. when I scroll down if I touch the image, the scroll is done correctly, however, if I touch the view the image is still here and a small scroll is done then when I scroll again the scroll is done right and the collection view takes the whole screen
After that when I scroll upwards, the same happens a small scroll happens then I have to touch again to do the scroll right and show the image.
EDIT: This GIF shows would clarify what I mean :
https://im2.ezgif.com/tmp/ezgif-2-75ed33ccd665.gif
Edit: The best solution was to create a TableView/CollectionView header and and my header in it and scroll normally for the table/collection view.
Old solution
The solution as provided in a comment by #MayurKarmur was to disable the scrolling in the collection view and adding height to collection view according to its content.

Gap above ContentView / not the same height as UIScrollview - xib

Issue: gap above where contentView starts. Should be 0.
Despite setting the content view top bottom leading and trailing to 0, the content view has a gap at the top. I am using auto layout only.
Scrollview background is blue &
Content view is grey for easy viewing.
If I set the content view to equal heights as the scroll view, I get an error. And this doesn't seem like the right approach away. According to this setting equal height is optional:
Apple auto layout scrollview page
I do set equal widths.
Entire Screen:
Top of Scroll view:
Bottom of scroll view -> this is right - flush with bottom of scroll view (not sure if that matters)
Constraints:
Subview constraints:
Please help!! Also I am using xib files - not sure if that matters.
Thank you!
You'll notice that the gap is equal in height to the navigation bar.
The gap is there because by default iOS assumes that when using a translucent navigation bar, scroll views (and their subclasses like table views) begin at the top of the screen, behind the translucent navigation bar.
iOS then assumes you do not want your content hidden behind the translucent navigation bar, so it applies a top content inset to any scroll view, of height equal to the navigation bar height.
This behavior can be overridden in two ways:
Unmark Adjust Scroll View Insets on the view controller (see image below)
Make your navigation bar not translucent. If you're using a Storyboard, select the navigation controller that contains the affected view controller, and unmark the Translucent checkbox.

UIScrollView in iOS doesn't response scroll to top

I have two UIScrollViews, one is horizental, the other is like page on the horizontal view. I want to click the status bar and have the vertical scrollView scroll to the top, but it doesn't work.
I searched for some information that said I must set UIScrollView.scrollsToTop=NO, but it doesn't work. Could somebody tell me why?
The scroll view only scrolls to the top if there is a single scroll view present with the scrollsToTop property set to YES.
Make sure it's set to NO on your horizontal scroll view and all the child, vertical scroll views contained within. Then, using the horizontal scroll view's delegate, as one vertical scroll view leaves the visible area, toggle the property to NO and toggle the incoming vertical scroll view's property to YES.

4 directional scrollview with paging

I need to implement a scroll view which (on a button press) will page either up, left, down or right depending on which button was pressed. Also the user can indefinately page in the same direction which will load the views in a kind of carousel. So I have 3 viewControllers.... viewController 1 is shown first....The user presses left, it shows viewController2, left again shows viewController3, left again is back to viewController 1 etc. and the same for up,down,right.
Does anyone know a good way to implement this? Im open to all suggestions.
Many thanks
Jules
Edit - second attempt at a clear explanation:
Consider this matrix.
This 3x4 matrix is the content area of your scroll view. With paging enabled, your scroll view will stop on one of these "cells", e.g. 2,1. That portion of the scroll view will be visible.
If you want each "cell" to be controlled by it's own view controller, then pre-generate all the view controllers (and their views), and then add all of their views as subviews to the scrollView.
You would populate this scroll view with whatever view you wanted to show at any given location. Set the frame of each view relative to the scrollview's origin. So if the cells were 320 pixels wide and 480 pixels tall, the frame for cell 1,3 would be CGRectMake(1*320, 3*480, 320,480).
When the scrollView ends deceleration, you can get it's contentOffset property, do some arithmetic and figure out which cell you're in.
To get the wrap-around effect, you'll have to do some trickery. You might put an extra cell at the end of each row and column, and if you find yourself in that cell, just set the scrollviews' contentOffset to the corresponding cell at the beginning of the row or column.

Setting UITableView contentInset also insets section header view

I'm changing my tableviews contentInset, so that when a user scrolls beyond the top bounds of the table, the tableview is inset to display a UISearchBar hidden above the tableView.
Everything works fine apart from the section header views. when scrolling down, the top bound of the sectionHeaderView is inset the same distance from the top of the screen as my tableview inset, here is it in starting position:
In the above image the sectionheader view is set to its correct positon, and the tableview inset has been set to display the search field.
You can see in this second screenshot where the top bound of the headerview is set lower because of the 43 pixel tableview inset, where as it should stick to the top of the screen hiding the "related" cell and bouncing back when released.
I guess i need to Offset the Inset somehow, i'm just not sure how..
I am assuming what you want is a search field like in the Mail application; a search field at the very top of the list that by default is not visible?
The solution is not to use contentInset, but instead:
Set a UISearchBar as the tableviews tableHeaderView.
Also add a UISearchDisplayController to the table view controller.
By default set the contentOffset to 44 points down, to hide the search bar.
Apple has a good sample app as a starting point here: http://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html