How to animate the width and height of a UIView in Xcode?

前端 未结 7 660
温柔的废话
温柔的废话 2021-01-30 23:27

I have this subview I want to add to my main view, but make it expand from the origin. I read some of the Apple documentation but I don\'t understand where I am making mistake.

7条回答
  •  醉话见心
    2021-01-31 00:00

    Important points

    1) Add view to your parentView before animation, with starting frame.

    2) Then just give target frame inside animation block

    You no longer need this since you are adding view from nib..

    //UIVIew yourView  = [[UIView alloc] initWithFrame:YOUR_STARTING_FRAME];
    //[self.view addSubview:yourView];
    
    .........
    .........
    .........
    

    just give the animation code on your view.. Make sure yourView is not nil (Seems to me that is the case..)

    NSLog(@"yourview : %@",yourView);
    [UIView animateWithDuration:your_duration 
                          delay:your_starting_delay 
                        options:UIViewAnimationCurveEaseInOut 
                     animations:^ {
                         yourView.frame = YOUR_TARGET_FRAME;
                     }completion:^(BOOL finished) {
    
                     }];
    

提交回复
热议问题