How to drag a row between other rows in UITableView or UICollectionView - ios

I am trying to implement the view shown in the animation below:
I found a great control called TGLStackedViewController which does almost what I need. The way it performs the moving is by taking a snapshot of the card you want to move and adding it as a subview to the collectionView, while hiding the original card. When dragging has stopped the movable view is removed and the original card is made visible again.
This works well, but doesn't produce the result I want since the movable view covers all cards. I wish for the card being moved to always be between the two cells above and below, just like in the animation. But I am not sure how to do this since all items are on the same level. I would really like to avoid making a completely custom view control and if possible do this with either UICollectionView or UITableView.

Related

Create Shazam Type UI ios Swift

I am trying to recreate a UIView I have seen in multiple apps, mainly Shazam. The top half of the screen has some interactive buttons, and the bottom half looks like a tableView with custom cells. When the bottom half is panned/swiped up, the tableView scrolls over the top half with velocity, much like a scroll view.
I have been researching this and experimenting for a couple days now. I have gotten close, but not quite there.
My last approach was a view that had a tableView inside it. When the view was panned, the view would move to wherever the finger moved it to, but then would not have any velocity afterwards. Also when the tableView was panned/swiped down, it wouldn't move the whole view down.
Before that I tried a scrollView that took up the whole length of the screen. That gave the desired effect, but the button wasn’t tappable, and you could scroll the view in the button area, which is undesired.
Does it utilize ScrollViews or is it using a tableView that acts much like a ScrollView somehow.
Here is the Shazam UI/UX I am looking to recreate:
The top portion has interactive buttons, and doesn’t scroll. The bottom half shows content and when scrolled, covers up the top portion.
Below is what I have tried so far: This one is the panning view, which sort of works, but doesn’t have velocity and the tableView doesn’t scroll the view back down.
Any thoughts on a direction I can take from here is greatly appreciated. I am using Swift.
Cheers
This sort of thing is perhaps best done with a collection view and a custom layout — you can have some items for which you set layout attributes absolute to the view, and others relative to the scroll content offset.
There's a great (if wandering) discussion of this and other techniques in the Advanced User Interfaces with Collection Views talk from WWDC 2014.
This is actually simple than it seems at first. Here's how you can achieve this:
Create a UIViewController (not a UITableViewController).
Add some buttons to the top area of the screen.
Add a table view spanning the entire view controller's view. Make sure the table view is on top of the buttons added in the previous step.
Configure the top cell of the table view to be transparent (by setting its background color to Clear). Set the background color on the table view to Clear as well. This way it won't obscure the elements at the top of the screen, unless the table is scrolled up.
Because your table view is now transparent, you'll need to explicitly set the background color on the table cells other than the top one.
Profit!

Adding a Scrolling Subview to a UITableView (NOT a Cell)

I'm creating my views programmatically. I have a UITableView in my UIViewController subclass that I want to add a scrolling subview to that is not a cell. I want to add some text-based subview to the UITableView that scrolls with the table and starts out above y=0 so the user will only see it if he pushes the table down. That is, it should reside above the first section of my table. If it helps for visualization, I intend to make something similar to those "scroll down to refresh" features and want some indication to the user that scrolling down causes a refresh. Is there any way to do this without something messy like using another UITableViewCell to represent it or abusing the UITableView delegate methods to move a view around whenever the user scrolls?
Simply using [tableView addSubview:] in my viewWillLoad only makes it appear for a split-second then disappear once the table data is loaded. This seems weird to me because UITableView is a subclass of UIScrollView, which is meant to hold other views in it. Using [tableView.backgroundView addSubview] does nothing.
P.S. Why not use a UIRefreshControl for this? I'm still undecided but leaning towards not using one because I don't like how slow that spinning wheel "feels" when the refreshes are usually very very quick. I've been looking at other options like flashing the background subtly and only showing a wheel if it's taking a longer time than usual.
I You can implement pull to refresh with only a table view
To do this using the scroll view delegate, since tableview is a subclass of scroll view.
Set view controller to be the tableview delegate and implement
(void)scrollViewDidScroll:(UIScrollView *)scrollView
When scrollview content offset y value passed a point, add a label to the viewcontroller.view not tableview. When you scroll back or release, remove the view.
You might also be able to add label to the table view and set the frame origin to negative y value, so when you pull the label will move into view (Never tested this do might not work)

How to create a layout like Featured page in App Store?

I'm new in iOS development. Based on my assumption, Feature page in App Store was created using a combination of UITableView and UICollectionView. But how to do that in theory and code? I know it's a bit vague, because it's quite hard to describe it, but I just need some people to help me explain it.
For this case I will try to use these naming:
1. Top section, it's a view which showing banners of apps, people can swipe it to view another banner.
2. Middle section, views which can be scrolled horizontally. (Best New Apps, Best New Games, etc).
3. Bottom section, starts from Quick Links to the bottom.
Questions:
1. The scroll indicator is starts from the root view's top guide, that's normal, but:
a. When we scroll it up, the bounciness is start from the middle section. How to do that? Is the top section and middle section is a separated view? But how can the scroll indicator is started from the root view's top guide if top and middle section is a separated view? (Separated view means that the views should have different scroll indicator unless it's actually subviews of UIScrollView).
b. When we scroll it down, there is nothing that floating. So it looks like that the whole page is a subview of a single scroll view but the bounciness is starts from the middle section. How to create that bounciness effect while only have one scroll indicator for the whole page?
2. In the middle section, there's a several collection view that has horizontal scroll direction. Is it the best way to create it like that is to use UITableView with cell that has UICollectionView inside it? It looks like it was created that way, but:
a. Is it the most efficient way to do that?
b. Because of the case in my first question is my source of confusion.
3. The bottoms section has a different separator from the middle section. The middle section has indentation while the bottom section doesn't. How can I do that if the case is it's a UITableView?
My whole question is just how to create a layout like that. If you cannot help me by providing me some sample codes that's fine, please just explain me the concept or theory of how to do that.
If the whole answer is just I have to create it using vertical/horizontal UIScrollView from scratch that's fine. I just want to make sure of that since I tried to avoid dealing with creating manual tiling.
OK, I think I finally found my own answer.
First, I need a UIScrollView to be root of the view. Then I set the contentSize to be a specific value.
The top section can be a UIPageController or a horizontal UIScrollView.
The middle section is a UITableView with scrollEnabled to NO and cells are static. The static cells (could also be dynamic cells) will contains UICollectionView. Since the scroll is disable, it will use the scroll from the parent UIScrollView. So that's why I can get the same bouncy effect in the middle section.
The bottom section is just another cell of a UITableView.
Thanks.
This might help you with implementing UICollectionViews in your UITableViewCell: http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell
To make the first cell "float" in the TableView you could make sure that cell never goes out of screen in scrollViewDidScroll

iOS UICollectionView not scrolling when cell is touched

I've created a simple grid based UICollectionView but I'm having trouble with the scrolling. If I touch the view itself rather than a cell within it then it seems to scroll correctly but if I touch one of the cells and try to scroll then nothing happens. This is a bit of an issue, as I basically want the grid of cells to completely fill the view, and when the view is filled like that there is nowhere to touch that will actually make it scroll! I guess the easiest way to describe what I'm trying to achieve is a table view but with two columns of cells rather than one.
I can't seem to find anything in the documentation that talks about this issue and I've tried various combinations of "user interaction enabled" settings etc.
One final thing, I do require the cells to respond to a single tap touch (basically to toggle them on and off) so I don't want to completely disable them responding to touches.

How do I speed up tap handling on a complex UITableView

I have an app with a TableView which is contained inside a ScrollView (horizontal pagination).
In each TableView is a custom TableViewCell which has a number of views.
To handle a singular tap on an area within the cell, I add a UITapGestureRecogniser to views within the cell.
Rendering performance is fine. But when I tap, I notice a sizeable delay from the point of tapping, to the point where the selector is called (i.e. I believe most of the time is being spent inside UIKit doing hitTests and finding out which element responds to what).
Is there a way to make this faster? What should I be looking out for that may be causing this problem?
You could try adding a single tap recognizer to a transparent view that fills the cells contentView, add it last so it's front most in the subViews array, then have it to the hit test for just the views of interest.
That said it would seem the delay comes from some other interaction.

Resources