Basic animation for UIView.frame

I am trying to make a simple animation of moving a frame from two views. Basically hiding an ad before loading it, and then moving the frame from the bottom, as well as the view that starts from the bottom, and then moves up when the ad clicks it. The start and end positions are correct, but I don’t see them being animated. It's right? Thanks.

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"frame"]; animation.duration = 1.0; CGRect adFrame = CGRectMake(self.adBanner.frame.origin.x, self.adBanner.frame.origin.y - self.adBanner.frame.size.height, self.adBanner.frame.size.width, self.adBanner.frame.size.height); self.adBanner.frame = adFrame; [self.adBanner.layer addAnimation:animation forKey:@"frame"]; CGRect buttonViewFrame = CGRectMake(self.ButtonView.frame.origin.x, self.adBanner.frame.origin.y - self.adBanner.frame.size.height, self.ButtonView.frame.size.width, self.ButtonView.frame.size.height); self.ButtonView.frame = buttonViewFrame; [self.ButtonView.layer addAnimation:animation forKey:@"frame"]; 
+2
source share
2 answers

For something as simple as this, you really don't need to use Core Animation directly - just use the built-in UIViews animation system.

 [UIView animateWithDuration:1.0 animations:^{ self.adBanner.frame = adFrame; self.ButtonView.frame = buttonViewFrame; }]; 

or, if you configure pre-4.0 iOS,

 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; self.adBanner.frame = adFrame; self.ButtonView.frame = buttonViewFrame; [UIView commitAnimations]; 
+12
source
 [UIView beginAnimations : @"Display notif" context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationBeginsFromCurrentState:FALSE]; CGRect frame = mainView.frame; frame.size.height -= 40; frame.origin.y += 40; mainView.frame = frame; [UIView commitAnimations]; 
+1
source

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


All Articles