Move a button from one UITableViewCell to another with animation in Swift - ios

I have a button and I want to keep track of which cell has the button with firebase. I can do this by putting the button in all cells and just make it visible in the one cell using firebase data. The part I'm stuck on is animating the button to move from one cell to another.
The only way I can think of is to put a delay on moving it from one to another, then have a separate animation happen. Then I think if I make the delay the same as the animation's duration then it will look like it just moved. I just thought of that while typing this but let me know if there's an easier/better way please!

This is a pretty tough thing to do, and animations can sometimes be one of the most difficult parts of mobile development. You aren't super clear on what your animation should look like, but since UITableViewCells each have their own contentViews I don't think directly animating the button from one cell to another is possible.
The best method I could think is to:
1) Draw a button on the screen at the location of the button you want to move
2) Hide the real button underneath
3) Animate this fake button over the tableview to the spot of the new, real button
4) End the animation and show the real button.
But you might have to block user interaction with the tableview while this happens to prevent them from scrolling and screwing up the animation...

Related

Hiding Specific Views When SearchBar Text Did Change

As newbie, I finally got a case project for internship. Before jump in directly to code, I would like to ask about a logic.
here how it is look like
As you can as see, I have a search bar in the top, and under that a page view and under that a collectionview. So I will display to first 3 data in pageview and rest of it will be displayed in collectionView. Whenever user start typing in searchbar, PageView must disappear and collectionview must go all the way to the top. (under searchbar) And collectionview must display the filtered data. Once user delete all text from search bar, everything should be like in the beginning and pageview must be in the same page before user typed in searchbar. (If it was in the 2. page, it must be in the 2.page after its displayed again)
Problem is with hiding pageview when searchbar is used. My idea is the create ui programmaticly and once textDidChange func of searchBar runs, hide pageView and change constraints of collectionview programmatically. Once text is nil, make pageview visible again and change constraints again.
Is this logic useful? Is there any better way to do it?
Your approach seems correct to me, that's how I'd do it as well.
To add an extra touch, you can also animate the layout constraints changes (by calling layoutIfNeeded in the animation block, look up "animate constraints" on StackOverflow).
And for a perfect user experience, make those animations reversible by using UIViewPropertyAnimator so that if the user typed a letter and then quickly erased it during the animation it would just reverse in the middle. It's a somewhat advanced technique but you'll gain a great deal of experience with animations by implementing it. Watch Advanced Animations with UIKit from WWDC17 for more details.

Animate TableView Cell to swipe left

I would like to make a simple animation in the first cell of a table view to indicate that the user can delete this cell!
I have already completed the delete feature of the cell, etc.
How is it possible to achieve this like a bounce animation?
Facebook has already done that if you go to the notifications for the very first time you go to that view.
1) You can take one view inside cell. Design it whatever way you like.
2) Set it frames like it want be visible on screen while designing.
3) To adding animation effect, you can use default UIView animation or you can refer UIKit dynamics to achieve spring and bouns effect.
4) Set view frames progamatically to come from right to left.
4) Rest of the logic to display only one time, you can write it by yourselef :-)

How to slide tableCell to show hidden interaction in UIAutomation iOS 7

I am trying to figure out how to get a hidden button to appear on table cell. Similar to if you were looking at the SMS app on iPhone. The threads are in table cells and if you touch and drag across that cell, a button to delete that thread appears. The functionality in my application is similar.
Now I would like to automate the testing of being able to delete a thread with this method.
target.frontMostApp().mainWindow().scrollViews()[0].tableViews()[0].visibleCells()[0].dragInsideWithOptions({startOffset:{x:0.9, y:0.5}, endOffset:{x:0.0, y:0.5}, duration: 1.5});
The above currently seems to start the intended interaction, but then the UI snaps back as if the action did not happen.
If you run this manually, does the cell stays on one side or does it always snaps back? The reason I ask is because I have a similar UI but I'm able to slide the cell all the way to one side and then tap on the buttons behind it. If you only drag the cell half way, then it will ignore the taps.

how to drag or drop multi uitableveiwcells on ios?

I want do drag a lot of selected cells and recorder them in my app.But I don't know how to do it.It seems apple just let u to drag one that what I have done it.
idea?
If it is ok to require that the selected cells are contiguous, then you can cheat by replacing them with a single tall cell.
EDIT:
For noncontiguous, the lazy solution would be to let the user select any cells, then after they drag and drop one of them, just move all the other selected cells right below it.
You could experiment with UITableView and see if it will let you animate out the other selected cells (with deleteRowsAtIndexPaths:withRowAnimation:) as soon as dragging is detected (possibly with UITableViewDelegate's tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:). You could also see if it will let you redraw/resize the cell when it begins dragging - then you could make it look like a z-layered stack or totem pole them into a tall cell while dragging.
Of course I'm assuming all the selected cells will share the same destination position. I can't wrap my head around noncontiguous sources to noncontiguous destinations in one drag-n-drop. If the user drags down 3 slots, does that mean you add 3 to the positions of all the selected cells? What if that takes a cell out of bounds? Even if you decided on some rules for odd cases like those and actually implemented this monstrosity, it could never be user friendly.
There is no easy way out. You need to handle the animation and movement by yourself.
Maybe you can take a copy of the cells you want to move and show an animation of moving to the destination.
When animation stops change the datasource.

iOS Development - Round Rect Buttons move down for sub menu

I have spent about 3 months now trying to figure out a problem and have finally turned to help. I have a menu with 5 round rect buttons. I want to know if theres a way I can make it so when I click the first button, the other four move down, to create space for a submenu under the first button. The same for the second, third, fourth, and fifth button. At the same time however, I want to make it so if the first button is clicked, the other four move down, and say the third one is clicked, four and five move even more down, and a scroll view launches when they can no longer all be displayed on the screen at once. Thanks in advance for all help :).
You can in fact do this. Here is an example for you. The jist is that you make a new IBAction which movies the coordinates when you press the button. So, if you have your method for what happens when you press the button, just add this to it:
button.frame = CGRectMake(button.frame.origin.x, (button.frame.origin.y), button.frame.size.width, button.frame.size.height);
As for changing where the buttons move, make a method like that and just add to the coordinates in order to move it. For example, if you wanted to move the above button up 150 pixels, you would do this:
button.frame = CGRectMake(button.frame.origin.x, (button.frame.origin.y - 150.0), button.frame.size.width, button.frame.size.height);
See what I did there? You just add or subtract from the frame to move the buttons where you want them to go.
I think you should put them all inside a tableView instead of a UIScrollView, (which is a scrollView itself) and override the heightForRowAtIndexPath methods according to your will. You may have to write a custom UITableViewCell for this and have a property to understand whether the cell is selected or not and switch it inside the didSelectRowAtIndexPath. Use tableView's beginUpdates and endUpdates methods at the end of the didSelectRowAtIndexPath to animate the movement of other subviews automatically.
You can also write animations for that by changing the origin of the UIButtons to move them, but I have tried it and with that number of subviews it becomes really messy, believe me. To see examplary code with dynamic row height and only one selectable cell you can have a look at: https://stackoverflow.com/a/13293380/936957. To enable multiple selection you can either have a NSMutableArray at the viewController/ UITableView's delegate or put a property of your custom UITableViewCell, like I've said before, both should work fine.

Resources