Animated Frame with CoreAnimation

I am trying to animate the position of some subviews in a scrollview. I want to create a specific effect when they are inserted. I just used implicit animation, changing the frame to UIView, but when they slide it looks too robotic. So I was hoping to create a bounce effect in which they glide inward, walk away a bit, and then return to my assumed position, pretty much what a scrollview looks like when it reaches the end, just the opposite.

In any case, I can not get it to animate the change in the beginning of the frame. I'm not sure what I am missing, because if I turn off what is being animated (do the first // * in / *), it just changes the opacity perfectly.

- (void)slideInStories; { float scrollViewContentWidth = 0; for (StoryViewController *storyController in storyControllers) { NSMutableArray *animationPoints = [NSMutableArray array]; CGRect viewFrame = storyController.view.frame; //* CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"frame"]; [animationPoints addObject:[NSValue valueWithCGRect:viewFrame]]; viewFrame.origin.x = scrollViewContentWidth - 10; [animationPoints addObject:[NSValue valueWithCGRect:viewFrame]]; viewFrame.origin.x = scrollViewContentWidth; [animationPoints addObject:[NSValue valueWithCGRect:viewFrame]]; /*/ CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"]; [animationPoints addObject:[NSNumber numberWithFloat:0.75]]; [animationPoints addObject:[NSNumber numberWithFloat:0.0]]; [animationPoints addObject:[NSNumber numberWithFloat:0.75]]; //*/ [animation setValues:animationPoints]; [animation setDuration:4.0]; viewFrame.origin.x = scrollViewContentWidth; scrollViewContentWidth += viewFrame.size.width; [storyController.view.layer setFrame:viewFrame]; [storyController.view.layer setOpacity:1.0]; [storyController.view.layer addAnimation:animation forKey:nil]; } [scrollView setContentSize:CGSizeMake(scrollViewContentWidth, 187.0f)]; } 
+4
source share
1 answer

You cannot animate a CALayer frame.

+5
source

All Articles