简体   繁体   English

滑动UIView动画

[英]Sliding UIView animations

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 我有一个按钮,在按钮操作中,我想通过从按钮滑动来显示我的UITableView,并且在单元格单击后它应该通过滑动效果而变起来。我是通过UIViewAnimation通过设置固定的y位置并将高度从0更改来实现的达到高度

       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 但这不是。我想要滑动效果。任何帮助都将是可贵的

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. 对于您的情况,我认为您应该使用UIViewAnimationOptionTransitionFlipFromTop作为幻灯片表格从上到下的动画选项。通过使用此选项,您的表格视图将在15秒内获得完整高度。 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. 

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 . viewDidLoad调用initComponents函数来设置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. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM