gpt4 book ai didi

objective-c - 使用 CoreAnimation 制作帧动画

转载 作者:可可西里 更新时间:2023-11-01 05:39:09 26 4
gpt4 key购买 nike

我正在尝试为 ScrollView 中某些 subview 的位置设置动画。我想在它们滑入时创建特定效果。我只是通过更改 UIView 上的框架来使用隐式动画,但是当它们滑入时它看起来太机械化了。所以我希望在它们滑入的位置创建弹跳效果,滑出一点,然后返回到它们的预期位置,这与 ScrollView 到达终点时的外观非常相似,恰恰相反。

无论如何,我无法让它为改变框架的原点设置动画。我不确定我错过了什么,因为如果我切换掉正在动画的内容(将第一个//* 设为/*),它可以很好地改变不透明度。

- (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 的框架设置动画。

关于objective-c - 使用 CoreAnimation 制作帧动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6039465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com