0

I have a button and in the button action I want to show my UITableView by sliding from the button and after the cell click it should goest up by sliding effect.I did it by UIViewAnimation by setting the fixed y position and changing the height from 0 to the height

       tableview.hidden=FALSE;
        tableview.frame = CGRectMake(0,myButton.frame.size.height,myButton.frame.size.width, 0);


        [UIView animateWithDuration:AnimationTime animations:^{

              tableview.frame = CGRectMake(tableview.frame.origin.x, tableview.frame.origin.x, tableview.frame.size.width,  200 );


        } completion:^(BOOL finished) {


        }];

But this is not .I wanted a sliding effect.Any help will be appreciable

Jeff
  • 1,405
  • 3
  • 26
  • 46

2 Answers2

1

Use this method for animation. Provide a option for animation style. There a lot of option in objective-c for animation style

[UIView animateWithDuration:15.0f delay:0.0f options:UIViewAnimationOptions animations:^{
        tableview.frame = CGRectMake(tableview.frame.origin.x, tableview.frame.origin.x, tableview.frame.size.width,  200 );
    } completion:^(BOOL finished)
     {

     }];

for your case i thought you should use UIViewAnimationOptionTransitionFlipFromTop as animation options for slide table from top to bottom.By using this your table view get its full height in 15 sec. you can mange that too.

EDIT:

Once you clicked on cell, you want that your tableview goes up with slide effect. Than use

[UIView animateWithDuration:2.0f delay:0.0f options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
            tableview.frame = CGRectMake(tableview.frame.origin.x, tableview.frame.origin.x, tableview.frame.size.width,  0 );
        } completion:^(BOOL finished)
         {

         }];

for slide up animation. 
Surjeet Singh
  • 11,691
  • 2
  • 37
  • 54
  • I also used the same method – Jeff Aug 05 '14 at 07:10
  • You are using similar method, not same. In this method you have 1 additional parameter option: which can be used for animation style. – Surjeet Singh Aug 05 '14 at 07:13
  • Sorry.I didn't get you.Can you please explain in detail.I don't know how to use it – Jeff Aug 05 '14 at 07:16
  • sorry for the late replay.There is no change. This is not like sliding. – Jeff Aug 05 '14 at 10:08
  • Suppose there are 5 cells,If its slide down then clle 5 should be visble at all time during slide down – Jeff Aug 05 '14 at 10:10
  • No, it will not look like you said. When you tap on cell, use UIViewAnimationOptionTransitionFlipFromBottom animation. It slides from last row to first. and when want to display table, use UIViewAnimationOptionTransitionFlipFromTop animation. First cell will visible first and then 2ns, 3rd. I had used this and work perfectly. – Surjeet Singh Aug 05 '14 at 11:18
  • It will work as you said.What i want is an animation like sliding.ie when it slide down ffith cell should show int the begining,then 4th,3rd.....When it slide up cell one should disappear first then cell 2,....last visible cell should be cell 5 – Jeff Aug 05 '14 at 11:37
0

Problem is not animation, problem is the frame you are defining. Easiest way to do this, is to define open and close frame and use them to animate.. See below..

Define Open and Close frame

-(void)initComponents{
    CGRect rect=tableView.frame;

    rect.origin=myButton.center;

    openFrame=rect;//Assign openFrame before changing the size.

    rect.size=CGSizeZero;
    tableView.frame=rect;

    closeFrame=rect;//Assign closeFrame
}

Call the initComponents function in viewDidLoad to set the initial state of your tableview. Now simply use the functions below on actions where you want to call.

-(void)openMenu{
   [UIView animateWithDuration:.3 animations:^{
        tableView.frame=openFrame;
    }];
}

-(void)closeMenu{
   [UIView animateWithDuration:.3 animations:^{
        tableView.frame=closeFrame;
    }];
}

Thats it. It should work.

Let me know. Cheers.

iphonic
  • 12,615
  • 7
  • 60
  • 107