- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试一个关键帧动画,其中 View 淡入,然后转换(平移和缩放),然后在延迟后再次转换,然后淡出。我遇到的问题是第二次转换在第一次转换结束后立即开始,而不是尊重延迟值。这似乎只发生在它再次修改变换时,所以我怀疑问题出在尝试在同一个关键帧 block 中进行两个不同的变换更改,尽管我不明白为什么不允许这样做,因为动画持续时间不重叠。
这是代码:
[UIView animateKeyframesWithDuration:15.0 delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^
{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.1 animations:^
{
self.imageViewCurrent.alpha = 1.0;
}];
[UIView addKeyframeWithRelativeStartTime:0.1 relativeDuration:0.1 animations:^
{
self.imageViewCurrent.transform = self.imageDataCurrent.transform2;
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.4 animations:^
{
self.imageViewCurrent.transform = self.imageDataCurrent.transform3;
}];
[UIView addKeyframeWithRelativeStartTime:0.9 relativeDuration:0.1 animations:^
{
self.imageViewCurrent.alpha = 0.0;
}];
}
// Fade in, pause, fade out.
CAKeyframeAnimation *alphaAnim = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
alphaAnim.keyTimes = @[@(0.0), @(0.1), @(0.9), @(1.0)];
alphaAnim.values = @[@(0.0), @(1.0), @(1.0), @(0.0)];
alphaAnim.duration = 15.0;
[self.imageViewCurrent.layer addAnimation:alphaAnim forKey:@"opacity"];
// Translate, wait on second translation, translate again.
CAKeyframeAnimation *transformAnim = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
transformAnim.keyTimes = @[@(0.3), @(0.4), @(0.5), @(0.8)];
transformAnim.values = @
[
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(self.imageDataCurrent.transform1)],
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(self.imageDataCurrent.transform2)],
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(self.imageDataCurrent.transform2)],
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(self.imageDataCurrent.transform3)]
];
transformAnim.duration = 15.0;
[self.imageViewCurrent.layer addAnimation:transformAnim forKey:@"transform"];
最佳答案
听起来您有一个时间轴,其中包含动画运行和“休息”的周期。我建议您将其余部分作为带有空动画 block 的关键帧输入。
像这样的东西:
[UIView animateKeyframesWithDuration:15.0 delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^
{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.1 animations:^
{
self.imageViewCurrent.alpha = 1.0;
}];
[UIView addKeyframeWithRelativeStartTime:0.1 relativeDuration:0.1 animations:^
{
self.imageViewCurrent.transform = self.imageDataCurrent.transform2;
}];
//Create an empty keyframe
[UIView addKeyframeWithRelativeStartTime:0.2 relativeDuration:0.3 animations:^
{
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.4 animations:^
{
self.imageViewCurrent.transform = self.imageDataCurrent.transform3;
}];
[UIView addKeyframeWithRelativeStartTime:0.9 relativeDuration:0.1 animations:^
{
self.imageViewCurrent.alpha = 0.0;
}];
}
关于ios - UIView animateKeyframes 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28181833/
我正在尝试一个关键帧动画,其中 View 淡入,然后转换(平移和缩放),然后在延迟后再次转换,然后淡出。我遇到的问题是第二次转换在第一次转换结束后立即开始,而不是尊重延迟值。这似乎只发生在它再次修改变
我正在尝试对标签进行动画处理,以在不同关键帧处使用不同的单词更改其文本,但它只是跳到最后一个关键帧(“晚安”),而不显示之前的关键帧。它确实打印了它们,所以我猜持续时间或开始时间有问题,但我不知道它可
我使用以下代码在 Swift 3 中使用 animateKeyframes 为按钮的比例设置动画: UIView.animateKeyframes(withDuration: 4, delay: 1,
目前有 2 个 CGAffineTransform 关键帧添加到 UIView.animateKeyframes。由于某些奇怪的原因,第二个关键帧的动画似乎没有发生。它只是在动画完成后立即跳回起始位置
我正在使用关键帧为标签创建一个简单的从左到右的动画,但是当动画重复时,延迟将被忽略。 第一次执行时,延迟3秒有效果,但当动画重复时,延迟被忽略。这会导致动画在结束后立即重新开始。 UIView.ani
我正在尝试为飞机起飞场景制作动画。我在这里使用 UIView animatekeyFrames 方法并提供所需的关键帧,但最后一个关键帧没有动画,我附上了一个 GIF,您可以在其中看到最终翻译中的故障
我正在尝试通过减少宽度约束来为 UIView 设置动画,但在使用 UIView.animateKeyFrames 时效果不佳。这是我的代码: UIView.animateKeyframes(w
我要么是愚蠢,要么误解了关键帧动画在 iOS 上的工作方式(或两者!)。下面的两个动画 block 产生不同的结果,但我希望它们是相同的: let duration: TimeInterval = 2
UIView 关键帧动画可让您创建通过一系列步骤进行的 View 动画。函数 animateKeyframes(withDuration:delay:options:animations:comple
我有两个 View Controller 。 AnimationVC 有一些 UIView 动画,而 DestinationVC 没有。 我有 CPU 使用问题。在我执行 segue 之后,动画 bl
我是一名优秀的程序员,十分优秀!