How do you drag-and-drop from a TableView's icon to a stationary icon? - iphone

How do we go about coding drag-and-drop (or tap-and-drag) from a cell in a TableView on an iPhone? I'd like to have a set of drop destination icons that are stationary. I've been trying touchesBegan, touchesMoved and touchedEnded methods. These events fire nicely from a View so I can get a swipe to work nicely. Most likely the destination icons will be in a View so I think we are trying to get the drag-and-drop to begin in a TableView cell and end on an icon on a View that is beside the TableView.

Are you trying to drag the entire UITableViewCell, or a UIView inside the cell? Either way, I don't think you'll be able to move the view outside the bounds of its parent, which would be the UITableView.
I have another project where I have a icon or tile (UIImageView) that the user can drag around the screen. After it reaches a certain distance, it snaps back.
Similarly, a possible solution might involve popping up a UIView (perhaps a UIImageView) over top of the table cell when the cell is tapped. The user could drag that around the screen, and you could make it disappear when it's "dropped" on whatever target you have.

Related

Drag UITableView or all TableViewCells to display a label

I'd like to create make a table view go to left when we swipe with a pan gesture. The goal is to display a label a the right of the table view like Instagram or iMessage for instance. Does anyone have a tip for creating this?
The result I would like to get.
https://i.stack.imgur.com/kDdSa.jpg
As a rough sketch, you may place a subview containing a timestamp inside your cell, below or to the side of the main subviews that display the content. You also will need to write a method that, depending on the pan progression, will show/hide this timestamp. Then you add a pan gesture recognizer to the table view itself, and, once panning, in your handler method you can call this disclosure method on the visible cells.

Overlaying buttons on tableviewcell with collectionview inside

I have implemented a image slider with a UICollectionView inside a UITableViewCell which the user can slide to left and right. I want to create two buttons on this UITableViewCell so the user can also tap on that buttons to slide the images.
I've done this by adding the buttons on the images inside the UICollectionViewCells but with that the buttons also are swiping when the user swipes to left or right or taps the buttons.
I tried to fix the buttons on the UITableViewCell, but anyhow the buttons does not get displayed, when I do it like this.
So how can I achieve this, that the buttons are fixed inside the UITableViewCell and the UICollectionView inside the UITableViewCell can move it cells without effecting these two slider buttons?
At storyboard it looks like this:
Can't rearrange the buttons:
Add the buttons directly to the content view of the table view cell, don't add them to the collection view. That way they will stay in position. If you can't see them it's possible that they were underneath the collection view and were obscured. Change the order of the views in interface builder by dragging and dropping in the document outline. This changes which view is on top.
The document outline is the view you have posted as a screenshot in your question, starting at "brandsCollectionTableViewCell". The outline contains the subviews of the cell. Views with the same parent, like the image view, label and buttons currently shown in the outline, will be ordered "on top" of each other by their position in the list. So you drag the items in that list to change the order, or select the buttons then go to Editor -> Arrange -> Send XX to adjust the position.
Use the Xcode view hierarchy debugger to help you understand what is happening (that's this button on the debugging toolbar):
The 3D view will let you see where your "missing" buttons are.
If you really want to include the buttons in the collection view, then you need to use a custom collection view layout implementing floating views. That's not a straightforward task, but I've written something about it here.

drag and drop from uitableviewcell to uiimage view in ios

I need help implementing a drag and drop gesture, I would like to know Your opinion to find the best approach.
I have a view controller with a uitableview on the right and some image views on the left.
I would like to allow the user to drag every cell of the table view on one of the image views. Basically the drag-n-drop will fail if the cell is not released on one of the image views, otherwise the image view will change image according to the dropped cell.
What do You think is the best way to achieve this?
In addition, when the user start dragging, I would like that he drags around a particular shaped subview, with image and data, not drag the semitransparent cell.
Thanks,
The basic steps for this would be:
Add a long press gesture recognizer to your table view (the whole view, not individual cells)
When the gesture begins, find which cell it is over (convert point, then user indexPathForRowAtPoint to get the cell)
Make a copy of that cell which will become the dragged view (take a snapshot, add it to a UIImageView and add that to your main view). Or you could make the view look however you want if you dont want it to look like the cell
make your original cell hidden so it looks like it is being dragged
On gesture changed, move teh position of this image view based on locationInView of the gesture)
On gesture ended, check to see if the cell is over an image (hitTest: for this) and do any animations or calculations you need.

How can I animate this custom view transition in my iPhone app?

This is a tricky question to explain, but basically I have an app with a home screen with a bunch of circular icons on it. When the user taps on an icon, it pushes a table view onto the navigation stack. When an icon is tapped on the home screen, I want the tapped icon to stay on top of the table view as it scrolls in, and then drop onto the table view in the cell that represents it. All the other icons, however, should stay below the incoming table view, like normal. Here's a quick diagram I whipped up...
I'm about to begin researching this, I just wanted to quickly post this question in case anyone has some ideas about how I can approach this. Thanks so much for your wisdom!
Oh thats soo easy!!!
I'll try to explain my solution:
You need two sets of icons.
One set lays on Home View, second is exact location, but as a subview on main window (by default - hidden)
Once You select a button, and want to push a list - You un-hide corresponding window subview icon, and with delay - animate / shrink it to tableView corresponding location.
Once animation is finished - hide icon (instant hide will not be noticeable, as this icon will be positioned/scaled to precisely reassemble icon in tableview), and move it to default position/scale (still hidden).
That's it.
This is pretty simple, and can be done without adding second instances of your buttons. You'll use the view hierarchies z-index for this.
When you add the table view as a subview of the main view don't use addSubview, use:
[self.view insertSubview:table belowSubview:button];
Button^ will represent the button that you want to stay on top, and for your other buttons, you just have to make sure that they are lower on the stack. This way, when the table flies in, it can keep going past the button but the button will stay above it.
You can also use:
[self.view insertSubview:table atIndex:5];
On all of these buttons and the table to have total control over each objects z-index.

Get on screen coordinates of a certain UITableViewCell?

So, I have this UITableView. It's in an iPad application. Some of the cells have an accessory button on the right (the small round arrow). When that is pressed, I present a popover view where the user can select actions related to the table cell that they touched. So far, nothing of this is difficult or exceptional.
But the popover view wants to know where it originates from, so that it can draw the little arrow pointing there. I would naturally like that arrow to point at the table cell the popover relates to.
How can I find out the current on screen coordinates for a certain cell in a table, given that I know it's indexPath?
Use the UITableView method -rectForRowAtIndexPath:. Note that that returns a rect within the table view’s coordinate system—if you need the rect relative to another view within the same window, use the UIView method -convertRect:fromView:.