How can I animate a UIView container to reduce its height?

I want to animate the size of my UIView container while my ad appears at the bottom. When it is ready, I will see an ad from the bottom of the screen. I want my UIView container to reduce the same size as the ad.

I created the outlet property for my container view in the top level of the UIViewController in which it is embedded.

Code of my advertising animation:

- (void)adViewDidReceiveAd:(GADBannerView *)view { NSLog(@"Received Ad"); [UIView animateWithDuration:1.0 animations:^ { view.frame = CGRectMake(0.0, self.view.frame.size.height - view.frame.size.height, view.frame.size.width, view.frame.size.height); // This is where I think I would need to animate the container view. }]; } 

How to reduce the size of my container view so that it matches the size of the ad? I need a container so that it stays in the same place and that’s all, but some height needs to be removed from the bottom.

+4
source share
1 answer

It's simple: just leave the frame of the container in the same block as the animation of your banner. It will be something like this:

 [UIView animateWithDuration:1.0 animations:^ { view.frame = CGRectMake(0.0, self.view.frame.size.height - view.frame.size.height, view.frame.size.width, view.frame.size.height); self.containerView.frame = CGRectMake( self.containerView.frame.origin.x, self.containerView.frame.origin.y, self.containerView.frame.size.width, self.containerView.frame.size.height - view.frame.size.height); }]; 

This piece of code will reduce your View container as the same height of your banner and at the same time. You can change / adapt as you wish.

Edit: if you use autorun, you must create an IBOutlet to limit and animate it, not the frame itself.

+2
source

Source: https://habr.com/ru/post/1501574/


All Articles