gpt4 book ai didi

ios - CAKeyframeAnimation keyTimes设置

转载 作者:行者123 更新时间:2023-12-01 18:11:57 27 4
gpt4 key购买 nike

这是我的代码:

- (void)animateImages
{
self.emoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 160, 50, 50)];
self.emoImageView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:emoImageView];

NSArray *values = [NSArray arrayWithObjects:
(id)[UIImage imageNamed:@"smiley64_1_1.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_2.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_3.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_4.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_5.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_6.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_7.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_8.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_9.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_10.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_11.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_12.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_13.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_14.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_15.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_16.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_17.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_18.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_19.png"].CGImage,
(id)[UIImage imageNamed:@"smiley64_1_20.png"].CGImage, nil];


NSMutableArray *keyTimes = [NSMutableArray arrayWithObjects:
[NSNumber numberWithFloat:0.00f],
[NSNumber numberWithFloat:0.04f],
[NSNumber numberWithFloat:0.08f],
[NSNumber numberWithFloat:0.12f],
[NSNumber numberWithFloat:0.16f],
[NSNumber numberWithFloat:0.20f],
[NSNumber numberWithFloat:0.24f],
[NSNumber numberWithFloat:0.28f],
[NSNumber numberWithFloat:0.32f],
[NSNumber numberWithFloat:0.36f],
[NSNumber numberWithFloat:0.40f],
[NSNumber numberWithFloat:0.44f],
[NSNumber numberWithFloat:0.48f],
[NSNumber numberWithFloat:0.52f],
[NSNumber numberWithFloat:0.56f],
[NSNumber numberWithFloat:0.60f],
[NSNumber numberWithFloat:0.64f],
[NSNumber numberWithFloat:0.68f],
[NSNumber numberWithFloat:0.72f],
[NSNumber numberWithFloat:0.76f], nil];


CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
[anim setKeyTimes:keyTimes];
[anim setValues:values];
[anim setKeyPath:@"contents"];
//[anim setCalculationMode:@"discrete"];
[anim setRepeatCount: 90000];
[self.emoImageView.layer addAnimation:anim forKey:nil];
}

动画将以固定的 UIImageView进行。帧之间的时间间隔为0.04。如果运行此命令,动画将以更快的速度播放。但是,如果我设置像 [anim setDuration:0.76];这样的持续时间,它会完美播放。我在这里做错了什么事?

最佳答案

我已经在回答您关于同一主题的其他问题时对此进行了解释。

关键时间是动画总间隔的分数,而不是几分之一秒。

在您发布的代码中,您根本没有指定任何持续时间。动画的默认持续时间必须短于0.2秒,因此,如果不提供持续时间,则会获得非常短的持续时间。如果指定较长的持续时间,则运行速度会变慢。

假设默认持续时间为0.2秒。您的keyTimes值相差0.04,并且
.2 * .04 = .008秒,即八千分之一秒。如果我是对的,并且动画的默认持续时间为.2秒,则您为每个帧设置了0.008秒。短于.01666秒/帧(1/60秒)的任何​​内容都是没有意义的,因为动画将不得不跳过帧。

实际上,由于文档未指定默认持续时间,因此当您未指定持续时间时,结果可能是不确定的。

关于ios - CAKeyframeAnimation keyTimes设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29110753/

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