Search code examples
iosxcodebuttonmenurect

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


Solution

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