Swift swipe from left to right [duplicate] - iphone

Apple shows these images on their product page for iOS 8. I am interested in adding buttons to the left side of a table row as shown in the first image. Is this a public API? Note that I am already aware of the delegate method for adding buttons to the right side. I've looked through the WWDC session videos and documentation to no avail.
Thanks in advance.
Pic: buttons on left
Pic: buttons on right

It's a public API to a point in iOS8, as explained in answers here Swipe to Delete and the "More" button (like in Mail app on iOS 7)
There are also several implementations already on Github, such as this one by MortimerGoro (part of the answer above).
If you want to do it yourself, you can use a custom UISCrollView or add subviews to your cell's contentView. Add gesture recognizers as appropriate to handle different swipe directions.
Essentially you reposition the button subviews with negative values as the gesture progresses, which gives the appearance of uncovering static buttons. In reality, everything is moving, just in opposite directions.
Ray Wenderlich.com has a very in-depth tutorial for how to recreate the effect.
It's also a right-sided button approach, but the concepts are identical - just swap the direction of the swipe gesture & where you place the button subviews.

You can use the tableview delegate method: leadingSwipeActionsConfigurationForRowAt
See Swipe Actions since iOS 11: Table Swipe Actions

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]{
let ackAction:UITableViewRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Himanshu", handler: myFunction)
ackAction.backgroundColor = UIColor.orangeColor()
return [ackAction]
}
edit: fixed code indentation

Related

Can't focus UICollectionViewCell inside UITableViewCell

so I am exploring the new tvOS. As I wanted to kind of replicate the horizontal feature section of the app store (e.g. "Best New Apps")
My plan was to use a UITableView to lay out the base structure (rows) and use an UICollectionView for all the individual horizontally scrollable items.
Unfortunately the tvOS always focuses the UITableViewCell, not the UICollectionViewCell inside. I've already read about the
override var preferredFocusedView: UIView? {
return aView
}
So using this inside my controller is kind of hard regarding getting the correct subview.
Is there anything I could look into or could someone please point me in the right direction? Iterating through all subviews until I get the correct one seems like a bad idea.
Thanks a lot!
I tried out a similar situation where I had a CollectionView within a CollectionView to get the setup you described. Let's call them innerCV and outerCV. To get innerCV to be focused and not outerCV's cells, I set this delegate method to return false for outerCV.
- (BOOL)collectionView:(UICollectionView *)collectionView canFocusItemAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
In turn, innerCV's cells are now focusable as opposed to outerCV's cells.
Credit for this goes to Apple. I used their sample project as a guide to start. Check out the Focus samples within their project.
Sample Project: Apple tvOS UIKitCatalog
I used a different approach..
Setting the tableview selection property to No Selection in storyboard makes the focus engine to focus on UICollectionViewCell cell rather than UITableViewCell.
Hope it helps :)
Image

iPhone / iPad UITable Swipe to Delete Resizes / shifts Cell

Is there anyway to turn off the Swipe to Delete resizing / shifting the cell? There is a custom cell that we are using that has a UIImageView as part of the cell display. When the swipe is done, it shifts to the left which is what we don't want. If we turn off autosizing in the IB, then the UIImageView does not shift, but then rotate is broke (UIView will not autoresize).
There are probably other ways around this, but was wondering if one can turn off the swipe to delete shift cells.
Ort11, don't touch "autosizing" (this is related to resizing when, for example, rotating - at least, that is what I think you mean). Instead, look at the UITableViewDelegate protocol. There is a method tableView:shouldIndentWhileEditingRowAtIndexPath:, for example. There also is a method to prevent editing for individual cells, in case you want to. All the best -
Perhaps this is what you're looking for?
UITableView disable swipe to delete, but still have delete in Edit mode?
In that you can no longer swipe to delete the cell, but you can still perhaps delete the cell by hitting the edit button.
Of course - this may not help with the moving of the cell parts; when the delete button appears on the cell the contents will still shift. You can override -(void)layoutSubviews in your UITableViewCell, to customize how the delete button will be positioned (more here: iPhone UITableView - Delete Button)

How to show custom options on swipe table cell in a simple way

I am working on a app which includes table cells. I want that when i swipe table cell it shows two options, first about that cell value and another for delete that value. How can i show that in a way that the cell value shows in half of cell and the options show in half of cell.
Thanks in advance.
There are an out of the box solution, called HHPanningTableViewCell. It does exactly what you need!
HHPanningTableViewCell is a UITableViewCell implementing "swipe to reveal" a drawer view. Such a view typically holds action buttons applying to the current row.
This library, SWTableViewCell, should help you:
https://github.com/CEWendel/SWTableViewCell
An easy-to-use UITableViewCell subclass that implements a swipeable content view which exposes utility buttons (similar to iOS 7 Mail Application)
You have to create a custom cell and override Apple's behavior which is swipe left to delete and then show your options. You can add gesture recognizer to the cell and on swipe to left animate the cell content view and animate in your option view or however you like it to be. I can write up an example code if you need.

UITableViewCell Swipe for Drawer

This is really more of a curiosity than a hard coding question.
Both Facebook and Twitter both have a feature where swiping a UITableViewCell animates the cell off the side to reveal a drawer with more controls underneath. How is something like that accomplished?
Here is a great open-source method for doing exactly this, based on the behavior of the Twitter app:
https://github.com/thermogl/TISwipeableTableView
This is a problem I have tried a couple of different solutions to. I really liked the behavior of Mailbox (mailboxapp.com). So I set out to achieve this. In the end I ended up with what I believe is a very simple solution: use a UIScrollView inside your cell. I have blog post that discusses and a sample app that demonstrates this behavior.
2 ways to detect swipt action
look at the willTransitionToState: method of UITableViewCell.
this method will be invoked when you swipe at the cell.
Custom swipe detection in a TableViewCell
and then you can change your cell view easily.
You could just implement -tableView:willBeginEditingRowAtIndexPath: in your table view delegate.
From the doc,
This method is called when the user swipes horizontally across a row; ... This method gives the delegate an opportunity to adjust the application's user interface to editing mode.
As a UITableViewCell is just a UIView, you can use this fact to basically do anything you like with it.
To solve your problem, I'd attach a UISwipeGestureRecognizer to detect the swipe and then animate the view to a different state.
For example, you could create a custom cell that has it's content view laying above the "actions view". Whenever there is a swipe, you use a UIView animation to move the content view aside and show the action view with a couple of buttons instead. In a custom UITableViewCell you could add a delegate protocol to have the pressed action and the cell being sent to the delegate, i.e. your controller. There you'd trigger what ever there is to trigger and then transition the cell out of the state.

Tweetie 2/Facebook-like swipe gesture in UITableview?

Hey everyone, I was just wondering if anyone knows how to create a UITableviewCell swipe effect akin to the one in the Tweetie 2.0 app (see video: Tweetie 2.0) or in the Facebook 3.0 app (when pressing the blue "+" next to a status).
What I need to do is to have the cell slide away in response to you swiping it and reveal a background view.
Any help would be appreciated!
Both Tweetie and Facebook implement their own 'custom' swipe detection. What I mean is that instead of using the standard UITableView hooks for swipes, you override touchesBegan:withEvent:, touchesMoved:withEvent:, et.c in your own subclass of UITableView. You can then start detecting swipes yourself and call whatever methods you want on your UITableViewCell's. (Hint: to get the cell given an UITouch, use the UITableView method indexPathForRowAtPoint:)
There's also a another plus to managing your own swipes: you get a lot more control over how accurate each swipe needs to be.