Objective c 使用CoreAnimation设置帧动画

Objective c 使用CoreAnimation设置帧动画,objective-c,ios,core-animation,cakeyframeanimation,Objective C,Ios,Core Animation,Cakeyframeanimation,我正在尝试为滚动视图中某些子视图的位置设置动画。我想在它们滑入时创建一个特定的效果。我只是通过更改UIView上的帧来使用隐式动画,但当它们滑入时,它看起来太机械化了。所以我希望创建一个反弹效果,让它们滑入,稍微远一点,然后回到它们的预期位置,就像滚动视图到达终点时的样子,刚好相反 无论如何,我不能让它改变帧的原点。我不确定我遗漏了什么,因为如果我将正在设置动画的内容切换(将第一个//*设置为/*),它只会很好地改变不透明度 - (void)slideInStories; { float

我正在尝试为滚动视图中某些子视图的位置设置动画。我想在它们滑入时创建一个特定的效果。我只是通过更改UIView上的帧来使用隐式动画,但当它们滑入时,它看起来太机械化了。所以我希望创建一个反弹效果,让它们滑入,稍微远一点,然后回到它们的预期位置,就像滚动视图到达终点时的样子,刚好相反

无论如何,我不能让它改变帧的原点。我不确定我遗漏了什么,因为如果我将正在设置动画的内容切换(将第一个//*设置为/*),它只会很好地改变不透明度

- (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)];
}

无法设置CALayer帧的动画

你试过了吗,只是为了踢踢,而不是给
中心设置动画?@Josh Caswell-是的,我可以做得很好。谢谢,这让我发疯了!我知道我在某个地方见过,但他说它是可动画的!文档错误?@JoshCaswell您已链接到UIView的frame属性。我不知道它是否可以制作动画。然而在@dustins发布的代码中,他专门将动画添加到层中。也许他也应该在UIView上使用基于块的动画方法?我没有直接在UIView对象上使用核心动画,所以我不能确定。动画层,而不是视图——你已经知道了。谢谢你指出错误。