标签: cabasicanimation

动画完成后,CABasicAnimation将重置为初始值

我正在旋转CALayer,并在动画完成后尝试将其停在最终位置.

但是在动画完成后,它会重置到其初始位置.

(xcode docs明确表示动画不会更新属性的值.)

任何建议如何实现这一目标.

iphone calayer cabasicanimation ios

132
推荐指数
11
解决办法
5万
查看次数

如何延迟CABasicAnimation?

我有一个,CABasicAnimation并希望在延迟后启动它.在UIKit我可以指定延迟.该CAMediaTiming协议有一个timeOffset属性,但我看不到效果.我的下一个尝试是使用GCD延迟它,但感觉有点矫枉过正.

core-animation uikit cabasicanimation ios

48
推荐指数
2
解决办法
2万
查看次数

有没有办法暂停CABasicAnimation?

我有一个iPhone的基本旋转动画.有什么方法可以"暂停"动画,以便保持视图的位置?我想这样做的一种方法是让动画"完成"而不是在其上调用"删除",我该怎么做?

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2];
rotationAnimation.duration = 100;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = HUGE_VALF;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.fillMode = kCAFillModeForwards;
[myView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
Run Code Online (Sandbox Code Playgroud)

iphone core-animation cabasicanimation

45
推荐指数
3
解决办法
3万
查看次数

CABasicAnimation无限重复没有HUGE_VALF?

我正在尝试使用CABasicAnimation执行我的图像旋转动画的自动重复.我试图在网上搜索如何设置这样的属性,但无法找到.CA动画真的没有这样的属性吗?我知道你可以设置一些巨大的值(这里)到repeatCount属性,但是,为什么UIView animateWithDuration有一个选项UIViewAnimationOptionRepeat以及该值是硬编码的呢?

iphone animation objective-c repeat cabasicanimation

40
推荐指数
2
解决办法
2万
查看次数

使用CABasicAnimation旋转CALayer后,图层会跳回到未旋转的位置

我想创造一枚落硬币.硬币图像是一个带有2个CABasicAnimations的CALayer - 一个掉落和一个旋转.当落下的动画结束时,它就会停留在那里.旋转动画虽然应该是随机的,但每次都以不同的角度结束,只会弹回原始的CALAyer图像.

我希望它保持在完成动画的角度.可能吗?我该怎么做?

码:

//Moving down animation:
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
anim.duration = 1;
anim.autoreverses = NO;
anim.removedOnCompletion = YES;

anim.fromValue = [NSNumber numberWithInt: -80 - row_height * (8 - _col)];
anim.toValue = [NSNumber numberWithInt: 0];

//Rotation Animation:
CABasicAnimation *rota = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rota.duration = 4;
rota.autoreverses = NO;
rota.removedOnCompletion = NO;
rota.fromValue = [NSNumber numberWithFloat: 0];
rota.toValue = [NSNumber numberWithFloat: 2.5 * 3.15 ];
[cl addAnimation: rota forKey: @"rotation"];
[cl addAnimation: anim forKey: @"animateFalling"];
Run Code Online (Sandbox Code Playgroud)

iphone calayer cabasicanimation

39
推荐指数
1
解决办法
3万
查看次数

如何在Swift(HUGE_VALF)中永远重复动画?

根据文档,永远重复CABasicAnimation的方法是将其设置repeatCountHUGE_VALF.

但在Swift中,HUGE_VALF会导致编译错误.Swift似乎不知道标准库(或者这个常量所在的位置).

现在我该怎么做?

cabasicanimation swift

38
推荐指数
2
解决办法
1万
查看次数

Core Animation无法使用"alpha"值

在此代码之前,我的电影pic alpha设置为0,

CABasicAnimation* fadein= [CABasicAnimation animationWithKeyPath:@"alpha"];
    [fadein setToValue:[NSNumber numberWithFloat:1.0]];
    [fadein setDuration:0.5];
    [[moviepic layer]addAnimation:fadein forKey:@"alpha"];
Run Code Online (Sandbox Code Playgroud)

没有任何事情发生,如果我事先将alpha设置为0.5,则alpha保持为0.5而不是动画为1.

我已经看过使用的代码UIView beginAnimations:了,但是我正在教核心动画,所以我想知道为什么CABasicAnimation不能做这样的简单任务?

alpha core-animation cabasicanimation ios

34
推荐指数
1
解决办法
1万
查看次数

iOS 8动画bug

我有一个简单的动画视图方法.

-(void)animateSelf
{
    CABasicAnimation * animation;

    animation = [CABasicAnimation animationWithKeyPath:@"position.y"];
    // settings ...
    [self.view.layer addAnimation:animation forKey:@"position.y"];

    animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    // settings ...
    [self.view.layer addAnimation:animation forKey:@"transform.rotation.z"];

    [UIView animateWithDuration: 1.0 animations:^{
        CGRect rect = self.view.frame;
        rect.origin.y += 800;
        self.view.frame = rect;
    } completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

对于iOS 7,它运作良好.但对于iOS 8,动画表现不可预测.有没有办法将这些动画组合到iOS 8中?

我试图用另一个CABasicAnimation替换animateWithDuration:但它没有帮助.view.frame日志是正确的,但view.frame的动画跳出了不明确的起源.

删除CABasicAnimation position.y(第一个)后,bug就消失了.

cabasicanimation ios8

22
推荐指数
2
解决办法
7009
查看次数

如何知道CABasicAnimation keyPath中的值

我找到一些像这样的代码:

CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"transform.scale";
anim.fromValue = [NSNumber numberWithFloat:1.0];
anim.toValue = [NSNumber numberWithFloat:0];
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeBoth;
anim.delegate = self;
[self.view.layer addAnimation:anim forKey:@"scaleOut"];
Run Code Online (Sandbox Code Playgroud)

anim.keyPath = @"transform.rotation.x";
Run Code Online (Sandbox Code Playgroud)

据我所知,keyPath是一个链式方法调用.CALayer的"transform.scale"是aLayer.transform.scale."transform"是CALayer的一个属性,"scale"是变换的"属性".但CALayer中的属性转换是CATransform3D.

CATransform3D中没有名为"scale"或"rotation"的属性.

我的问题是:keyPath如何识别"缩放"和"轮换"?

iphone calayer cabasicanimation

21
推荐指数
2
解决办法
2万
查看次数

如何在iOS应用程序中链接不同的CAAnimation

我需要链接动画,CABasicAnimation或CAAnimationGroup,但我不知道如何做,我唯一做的是所有动画同时执行同一层.

我怎么能这样做?

例如,一个内容设置为汽车图像的图层:

1st:将X点向右移动

第二名:向左旋转90ª

第3名:移动X点

第四步:缩放图层

所有这些动画必须以一种安全的方式执行,但我不能这样做:S

顺便说一句:我不是英国人,对不起,如果我在语法上犯了一些错误:D

core-animation cabasicanimation caanimation

20
推荐指数
3
解决办法
1万
查看次数