Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When UIView height set zero, view's child control not hide

I want drawer animation. So I take 1 UIView and add 4 control inside UIView. Now when I click on drawer button, set view height zero when drawer is close and set view height 200 when drawer is open.

But when I set zero height, button is not hide . All buttons are visible. Auto layout is not in my project.

How to solved this problem.?

-(IBAction)Onclick_drawer:(id)sender
{
    if(is_open)
    {
        is_open=false;
        [UIView animateWithDuration:0.3
                              delay:0.0
             usingSpringWithDamping:1.0
              initialSpringVelocity:4.0
                            options: UIViewAnimationOptionCurveEaseInOut
                         animations:^{

                             self.drawer_view.frame=CGRectMake(0, 64, 320,200);
                         }
                         completion:^(BOOL finished){

                         }];
        [UIView commitAnimations];
    }

    else
    {
        is_open=true;
        [UIView animateWithDuration:0.3
                              delay:0.0
             usingSpringWithDamping:1.0
              initialSpringVelocity:4.0
                            options: UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             self.drawer_view.frame=CGRectMake(0, 64, 320, 0);
                         }
                         completion:^(BOOL finished){

                         }];
        [UIView commitAnimations];
    }


}
like image 503
Monika Patel Avatar asked Mar 23 '16 05:03

Monika Patel


3 Answers

check in xib ... select view -> attribute inspector -> check clip Subviews like below image

enter image description here

or programatically use

   self.yourview.clipsToBounds = YES;
like image 177
EI Captain v2.0 Avatar answered Nov 20 '22 13:11

EI Captain v2.0


Just select the view and go to right side of screen into attribute inspector

Check the check box for Clip Subviews

enter image description here

like image 20
Harshal Bhavsar Avatar answered Nov 20 '22 14:11

Harshal Bhavsar


-(IBAction)Onclick_drawer:(id)sender
{
    if(is_open)
    {
        is_open=false;
        [UIView animateWithDuration:0.3
                              delay:0.0
             usingSpringWithDamping:1.0
              initialSpringVelocity:4.0
                            options: UIViewAnimationOptionCurveEaseInOut
                         animations:^{

                             self.drawer_view.frame=CGRectMake(0, 64, 320,200);
                         }
                         completion:^(BOOL finished){

                         }];
        [UIView commitAnimations];
    }

    else
    {
        is_open=true;
        [UIView animateWithDuration:0.3
                              delay:0.0
             usingSpringWithDamping:1.0
              initialSpringVelocity:4.0
                            options: UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             self.drawer_view.frame=CGRectMake(0, 64, 320, 0);
                             self.drawer_view.clipsToBounds = YES;  // Need to add this line. This will clip all sub views into parent view 
                         }
                         completion:^(BOOL finished){

                         }];
        [UIView commitAnimations];
    }


}
like image 1
Yagnesh Dobariya Avatar answered Nov 20 '22 13:11

Yagnesh Dobariya