SWRevealTableViewCell icon indicating copy to clipboard operation
SWRevealTableViewCell copied to clipboard

Question - Best way to slide the menu back when beginning the touch on the buttons

Open FramusRock opened this issue 10 years ago • 9 comments

Hey,

It's me again, this time with a question: What do you think is the best (and easiest) way to be able to slide the reveal menu back on the revealed buttons?

The first idea that came to my mind was to add a GestureRecognizer with the exact same functionality as on the TableViewCell to the revealed buttons.

Is there an easier way than this?

I hope you have some time answer ;) Best, Max

FramusRock avatar Aug 25 '14 02:08 FramusRock

Hi @FramusRock . Not sure if I understand the issue. Do you mean implementing a way to set the cells to the default position (no button items revealed) when you tap onto another cell?. If so, I guess one way is to implement the willSelectRowAtIndexPath tableview's delegate to dismiss all visible cells. Or maybe the class can be enhanced to provide a custom delegate for that (?). Thanks

John-Lluch avatar Aug 25 '14 07:08 John-Lluch

Sorry, I maybe wasn't clear enough. Let's say we have three buttons behind the cell on the right side. Now the user slides the cell to reveal the buttons. Now he wants to "close" the cell again by swiping in the other direction without doing anything. My issue here is that the closing swipe/drag can only be origined from the cell itself (so from the little part of it that might be still visible).

I'm searching for a way that allows the swipe/drag gestures also to be started from one of the (three) buttons.

FramusRock avatar Aug 25 '14 08:08 FramusRock

Oh, I see. I haven't thought on that. Currently, the pan gesture recognizer is added to the cell's 'contentView' view. This is why the recognizer is only available on that portion of the cell. So maybe we can experiment by adding the recognizer to the view that holds the buttons or even to the entire cell. Not sure if this would break something.

By the way, how does the mail app behave?, does it allow you to swipe/drag the cell the way you describe?

Please try this: on the _initSubviews method replace this

    UIView *contentView = self.contentView;
    [contentView addGestureRecognizer:_panGestureRecognizer];

by this

    [self addGestureRecognizer:_panGestureRecognizer]; 

Does that do what you want?

thanks

John-Lluch avatar Aug 25 '14 08:08 John-Lluch

Ah okay it works like that, I was scared it wouldn't be as easy as this. But that works like a charm, thank you!! That was a really easy and cool fix ;)

Apple Mail behaves like your cells do by default. I've just got a rather small cell with three buttons behind it, so the space where the user might start touching is quite small.

FramusRock avatar Aug 25 '14 08:08 FramusRock

Anyway I liked your proposal. I guess in our case we can make it an initialization option, so its easier for developers to chose what suits them best.

John-Lluch avatar Aug 25 '14 08:08 John-Lluch

Cool, I'm glad you like it!

FramusRock avatar Aug 25 '14 09:08 FramusRock

After a big more testing I think we'll need to add the recognizer (or another recognizer) to the view that holds the buttons. The problem I'm facing right now is that the user can no longer efficiently reorder TableViewCells with this setup. The PanGestureRecognizer always wants to be the first to be fired, so the cells will nearly always slide to the side (even if just a tiny bit) instead of letting it being reordered.

So even if the user touches the three vertical bars for reordering, so he absolutely wants to reorder he can't in 80% + of the tries I made.

I tried to enable simulatenous gesture recognizers but also that does not help here.

FramusRock avatar Aug 25 '14 11:08 FramusRock

I tried adding an additional gestureRecognizer to the utilityContentView once the reveal menu is fully revelaed and removing it again once the menu is not visible. This leads to a better result but it's still not perfect. Just adding the recognizer to the utilityContentView (w/o removing it again on disappear) still leads to messy reordering.

Did I add the recognizer to the wrong view? Do you have an idea how to do this better?

Thanks

FramusRock avatar Aug 25 '14 12:08 FramusRock

I tried it a bit more and got it to work, using the utilityContentView for the second gesture recognizer was fine, I just made a stupid mistake before.

FramusRock avatar Aug 25 '14 13:08 FramusRock