Question

I've tried every thing I can think of, and nothing is working.

Similar to the effect in iOS 7's Mail.app, I want to be able to slide the cells of my table view right and left. I want to be able to do this in a Storyboard and Auto Layout, as most of my app is done with those. I understand scroll views with Storyboards calculate their contentSize by the constraints of their subviews.

With that, I've predominantly tried two strategies. The first, just have a label in the scrollview that I can slide right or left. I set it to be stuck to the top of the scroll view and the bottom, but 300pts on either side of the label to allow the scroll view to calculate its contentSize. This pushes the label enormously to the right so I can't see it when the table loads.

Option two, the preferable one, is to put a UIView in the scroll view, and then put the label and whatnot within that so they can be all positioned as a group with their UIView parent. I've tried simply setting the UIView here, setting it to be stuck to the top and bottom of the scroll view, the width is set to 320, while the left and right side are 320 away from the edges.

This complains that there's no height constraint, but I told it to stick to the top and bottom of the scroll view. How does that not count? If the cell size grows, the scroll view is set to grow with it, and as a result I want the inner view to grow in height as well. It also complains of the position horizontally for some reason.

enter image description here

Here's an example project with all the constraints mentioned.

What on earth is going on? Is this an impossible task?

Was it helpful?

Solution

I would add a scroll view to each cell's contentView.

I would set the scroll view width to one-third of the with of the cell, set paging enabled and not to clip its subviews.

enter image description here

Then add a "real" content view inside with the width of the cell that will hide the underlying buttons.

Finally you have to set programmatically the correct contentSize (width of the cell) and initial contentOffset (one-third of the width).

You can also play with the scroll view contentInsets to further adjust it.


Sample Nib code here.

OTHER TIPS

Unfortunately, I think the answer is that what you want to do is impossible in pure Storyboards. You'll need code to provide animation or a transition between Views.

Your question is if you can make an UITableViewCell draggable?

If I understood right the answer, you could get 2 content view:

  1. The back view
  2. The draggable view

Then, you should add a custom UIPanGestureRecognizer to UITableViewCell, and with this you detect how many pixel you drag the cell (only on x values if you want only drag on x values), and finally you only should update draggable view's origin.x with the pan value.

If it's not what you are looking for, please be more precise in question and I'll give you a correct answer :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top