position of cell with orientation - ios

I have a collection view with 5 rows with each row consisting of 3 cells in each row in Portrait orientation on the view. In landscape, it has 3 x 4 cells, with half visible 4th row. For example, if a cell index is 5, it appears as below:
Portrait - second row, second cell.
Landscape - Second row, first cell.
If for instance, in Portrait mode, the collection view is scrolled down with an offset. And if the orientation is changed to Landscape, is it possible to
1) find out the exact position of the cell after applying appropriate content offset?
2) find out the scroll offset in the new orientation?
I will need the position without reloading the view in the orientation. By position, I mean the center of the cell. And the scroll offset too?
Would it be possible? Would it be a right approach, if I load the contents on an offscreen collection view and scroll to the cell to find its position?
Please help!!

I have tried a work around here.
I am trying to reload the collection view with the change in orientation and scroll to the selected cell at scroll position UICollectionViewScrollPositionCenteredVertically. Now, I know the position of the cell according to the cell index.

Related

Scroll Tableview Cell with outer Scrollview instead of It's own scroll ?

I have an Imageview covering half of the screen height and a tableview below it. Both are wrapped inside a UIScrollView. I want to scroll the whole view. Means inner scroll of tableview won't work and when I scroll, outer scroll will scroll image view up and then showing cells of tableview. At the end, Imageview will hide behind scroll and tableview content will take entire space. Can anybody tell me how to achieve this. ?
Thanks
I don't think you need the outer scroll view(UIScrollView). Why don't you add only the inner table view and image view to where your outer scrollview is added. The image view can be added either above or below the table view. Let say your image view is below the table view then your image view will be covered by table view. In order to make it fully visible, set the talbview's content inset top to imageview's height and its background to clear color. then you can see both image and table view contents without one covering the other. The last thing you need to do is you have to handle the image view's y position when you scroll the table view so it looks like they are in the same scroll view. Use the scroll view delegate that is already available to you and play with scroll view's content offset and image view's y position.
I answered some similar question here with some sample code. Hand off parent container's pan gesture to nested UICollectionView
It does with collection view but the main idea is same.

Displaying a cell always at least at the bottom of the screen

We got UI specs for a change in a page with a table view. The last cell of this table view should be at the bottom of the page. However, if the table view content is longer then the page, then the cell should scroll.
Here are two approaches that I have tried, with success:
Have a UIView of the cell content with a constraint to the bottom of the page, as well as the cell in the table view. If the table view content height < the view height, hide the cell from the table view and use the UIView instead.
Have a buffer cell between the rest of the table view and the final cell. In the viewDidAppear, since it seems to be the place where the table view elements have their height, get the sum of the height of the other cells of the table view. If this sum is smaller then the screen size, set screen size - cellsHeight to a View controller variable, and trigger a table view reload. In the heightForCellAtIndexPath function, when rendering the buffer cell, use the variable's height to define the buffer height. In the first calculation it will be 0. in the second table view calculations , it will be 0 if the cell need to scroll, or whatever the calculation returned if it needs a buffer.
I feel like both of these solutions are dirty. Are there any better way to approach this problem? If not, is there a way to run the second solution without two data reloading?

How to display the entire contents of the a TableView while in Landscape mode

I have a TableView controller, and the tableView cells were added statically.
as shown in the image_1 below, I have 18 cells. but the problem I have now is, when I change the screen orientation to Landscape, the simulator can not display the entire cells inside the TableView controller, it displays only 8 cells as shown in image_2.
please let me know how to display all cells while in landscape mode.
image_1:
image_2:
If you want to fit all the cells, I think, you can either check the current orientation and decrease the cell heights or You always can use collection view and also change the item sizes relative to orientation.

UICollectionView with pagingEnabled - get content to stop at top

The collection view has a frame of 320x400, and the cells have a size of 320x320. The collection view scrolls vertically with pagingEnabled = YES. So at any time you can see one cell and part of another cell below. When you scroll up, I need each cell to stop at y=0.
Right now what happens is that each time you page upward, the cell stops at a higher position on the screen and does not stop at y=0. I think this is because the collection view pages based on it's own height of 400. How can I override this to stop on each cell?
I've tried subclassing UICollectionViewFlowLayout and overriding targetContentOffsetForProposedContentOffset, but I can't get it to work. Is there an easier way?
You can set the Flowlayout's minimumLineSpacing to 60 (400 height-320 height). with paging on, that should give you perfect page.

Unnecessary padding in tableview cell iOS?

I am developing an enterprise iOS application that uses splitview to display information. My split view, tabbars are all in place and seem to work fine. I have a tableview in the left pane of the splitview. The tableview has custom cells which contain an image view and several textview (removed textviews in the img) The height of the image view is same as the row height of the tableview and tableview cell. I wish to achieve a row height of 182 points. Even though I have kept all size same I see a padding on the left, top and bottom of the tableviewcell. In the tableview the cells thus appear separated by the background color. The tableview has no separators set. The only problem I see is that the image used inside the cell is only 168 points in height.
I did the same stuff in the detail view in the split view however now I see the table cells occupying the entire area designated to it. The image inside this detail view cell is only 160 points in height yet to I do not see that "padding" effect.
I have attached a sample screenshot, pls let me know where to fix it?

Resources