iOS Development - Round Rect Buttons move down for sub menu - ios

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.

Related

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

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...

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 :-)

allow user to tap label and then tap buttons to edit label.text?

So what I have right now i table with multiple cells. Each cell has two UIlabels. Underneath the table are a bunch of buttons with different int values. I want to allow the user to tap on a label and then tap on the buttons to change the text of the label to whatever buttons they press. Eg if they press buttons, "1","2","3" the label will display 6.
I think i managed to figure out how to find out which label has been touched, but I'm stuck afterwards as i can't figure out how to get the button pressing part to work. Any ideas? thanks in advance!
To know which UILabel has been touched add a tap gesture to each label which triggers an action. In that actions store which label has been touched in e.g. a property.
For the buttons, just connect them to action methods (could also be a single one), inside these methods do your calculation and updated the label indicated by the property described above.

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.

I need to detect a swipe gesture on my tableView that is within a page control, how can I do this?

Pretty straight forward, I just can't get it to work. What can I do to swipe to delete on my tableView that is within a page control?
Please help!
Edited to remove my original answer regarding the proper UITableViewDataSource methods.
This sounds like a potentially complicated user interface (i.e. if users are expecting swipes to turn a page but if they mis-touch and hit the table view cell just right, they'll get the "delete" button). I'd suggest re-thinking what you are doing.
In any event, to get to the finish line on your app might be to subclass UIPageControl, detect when swipes are happening in the content region and pass that swipe message along to the table view. I suspect you can't just do userInteractionEnabled = NO; on the page control's content view.
F.Y.I.: you should also probably delete the identical & duplicate question you posted a number of hours before the question I'm attempting to answer ( How can I capture a sideways swipe gesture for a tableView that is inside of a pageControl? )

Resources