开发者

Animating Frame with CoreAnimation

I'm trying to animate position of some subviews in a scrollview. I want to create a specific effect as they slide in. I was just using implicit animation by changing the frame on UIView but when they slide in it looks too robotic. So I was hoping to create a bounce effect where they slide in, go a bit to far, and then go back to their intended position, pretty much to how a scrollview looks when it reaches an end, just sort of the opposite.

Anyways, I can't get it to animate changing the frame's origin. I'm not sure what I'm missing, because if I switch out what is being animated (make the first //* to /*) it works just fine changing the opacity.

- (void)slideInStories;
{
    float scrollViewContentWidth = 0;

    for (StoryViewController *storyController in storyControllers) {
        NSMutableArray *ani开发者_如何学PythonmationPoints = [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)];
}


You cannot animate the frame of a CALayer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜