Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving UIView from bottom to top

How can I move a view from bottom to top on my code:

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];

So how can I add the animation here?

like image 891
Naveen Avatar asked Apr 08 '13 02:04

Naveen


People also ask

Does UIView animate need weak self?

No, it is not needed in this case. animations and completion are not retained by self so there is no risk of strong retain cycle.

Does UIView animate run on the main thread?

The contents of your block are performed on the main thread regardless of where you call [UIView animateWithDuration:animations:] .

How do you animate a view in Swift?

To be exact, whenever you want to animate the view, you actually call layoutIfNeeded on the superview of that view. Try this instead: UIView. animate(withDuration: 0.1, delay: 0.1, options: UIViewAnimationOptions.


2 Answers

Initially, add your view:

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

For the animation from bottom to top add below:

[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];

For removing the view

[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];
                         }];
like image 150
3 revs, 3 users 92% Avatar answered Jan 03 '23 23:01

3 revs, 3 users 92%


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];
                     }];
like image 27
Waqas Ali Avatar answered Jan 03 '23 22:01

Waqas Ali