从底部向上移动UIView

6
我该如何在我的代码中将视图从底部移动到顶部:
colorView.hidden=NO;
colorView=[[UIView alloc]init];
colorView.frame=CGRectMake(0,480,320, 480);
colorView.bounds=CGRectMake(0,200,320, 280);
colorView.backgroundColor=[UIColor greenColor];
colorView.alpha=1.0f;
[webView addSubview:colorView];
[self.view addSubview:webView];
[self createTransparentView];

那么我该如何在这里添加动画效果呢?

你尝试了什么?在提出这个问题之前,你做了哪些研究? - autistic
你可以在视图层上使用CATransition。https://dev59.com/Y2sy5IYBdhLWcg3w-i_h#23195924 - Warif Akhand Rishi
3个回答

55

一开始,添加您的视图:

self.postStatusView.frame = CGRectMake(0, 490, 320, 460);

对于从底部到顶部的动画,请添加以下内容:

[UIView animateWithDuration:0.5
                      delay:0.1
                    options: UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     self.postStatusView.frame = CGRectMake(0, 0, 320, 460);
                 } 
                 completion:^(BOOL finished){
                 }];
[self.view addSubview:self.postStatusView];

移除视图

[UIView animateWithDuration:1.5
                              delay:0.5
                            options: UIViewAnimationOptionCurveEaseIn
                         animations:^{
    self.postStatusView.frame = CGRectMake(0, 490, 320, 460);
                         }
                         completion:^(BOOL finished){
                             if (finished)
                                 [self.postStatusView removeFromSuperview];
                         }];

postStatus 是你的视图名称,对吗? - Naveen
1
应该是 UIViewAnimationOptionCurveEaseIn(重点在于 Option)吗? - Brian White
3
在Xcode 6.1中,将UIViewAnimationCurveEaseIn替换为UIViewAnimationOptionCurveEaseIn,然后它就可以工作了。 - byJeevan
1
这段代码实际上有效吗?对我来说没有任何作用,只是在正确的位置添加视图。 - Ace Green
如何实现从顶部到底部的动画效果...我的子视图应该放置在x:7,y:70。同样地,也可以实现从底部到顶部的移除效果。 - Abirami Bala
@AbiramiBala 只需使用X位置值进行动画处理,上述代码处理的是Y位置值。 - Vinodh

3
self.colorView.frame = CGRectMake(0, 490, 320, 460);

[UIView animateWithDuration:0.5
                 delay:0.1
                options: UIViewAnimationCurveEaseIn
             animations:^{
                 self.colorView.frame = CGRectMake(0, 0, 320, 460);
             } 
             completion:^(BOOL finished){
             }];
[self.view addSubview:self.colorView];

[UIView animateWithDuration:1.5
                          delay:0.5
                        options: UIViewAnimationCurveEaseIn
                     animations:^{
self.colorView.frame = CGRectMake(0, 490, 320, 460);
                     }
                     completion:^(BOOL finished){
                             [self.colorView removeFromSuperview];
                     }];

2
不仅仅是抛出一些代码,解释正在做什么以及为什么会更有用。 - David Berry

0
self.tableView.frame = CGRectMake(0, 490, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);

[UIView animateWithDuration:.35
                      delay:0.0
                    options:  UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     self.tableView.frame = CGRectMake(0, -20, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
                 }
                 completion:^(BOOL finished){
                     [UIView animateWithDuration:0.1   delay:0.0
                      options:  UIViewAnimationOptionCurveEaseInOut   animations:^{

                         self.tableView.frame = CGRectMake(0, 20, [[UIScreen mainScreen] bounds].size.width , [[UIScreen mainScreen] bounds].size.height);

                     } completion:^(BOOL finished){

                         [UIView animateWithDuration:0.1   delay:0.0
                          options:  UIViewAnimationOptionCurveEaseInOut animations:^{

                              self.tableView.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);

                         } completion:^(BOOL finished){

                }];
        }];
 }];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接