Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 动画在结束或触发第二个动画后重置为开始状态_Ios_Objective C - Fatal编程技术网

Ios 动画在结束或触发第二个动画后重置为开始状态

Ios 动画在结束或触发第二个动画后重置为开始状态,ios,objective-c,Ios,Objective C,我正在尝试制作一个呼吸循环动画。只有呼吸(生长循环)似乎是有生命的。BreatsoutAnimation(收缩圈)被调用,但似乎什么都不做。我猜它会立即恢复到起始状态,但我不明白为什么 -(无效)viewDidLoad animationView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2.0, self.view.frame.size.height / 2.0, 200, 200)];

我正在尝试制作一个呼吸循环动画。只有呼吸(生长循环)似乎是有生命的。BreatsoutAnimation(收缩圈)被调用,但似乎什么都不做。我猜它会立即恢复到起始状态,但我不明白为什么

-(无效)viewDidLoad

 animationView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2.0, self.view.frame.size.height / 2.0, 200, 200)];
 animationView.backgroundColor = [UIColor blueColor];
 animationView.layer.cornerRadius = 100;
 animationView.center = self.view.center;
[self.view addSubview: animationView];


[self drawCircleEdge];
[self breathInAnimation];
[NSTimer timerWithTimeInterval:7.0 target:self selector:@selector(breathOutAnimation) userInfo:nil repeats:YES];
-(无效)呼吸

    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    [scaleAnimation setValue:@"breathIn" forKey:@"id"];
    scaleAnimation.duration = 4;
    scaleAnimation.fromValue = [NSNumber numberWithFloat:0.1];
    scaleAnimation.toValue = [NSNumber numberWithFloat:1];
    [animationView.layer addAnimation:scaleAnimation forKey:@"scale"];
    CABasicAnimation *breathOut = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    breathOut.duration = 8;
    breathOut.fromValue = [NSNumber numberWithFloat:1];
    breathOut.toValue = [NSNumber numberWithFloat:0.1];
    [animationView.layer removeAllAnimations];
   [animationView.layer addAnimation: breathOut forKey:@"scale"];
-(无效)呼吸动画

    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    [scaleAnimation setValue:@"breathIn" forKey:@"id"];
    scaleAnimation.duration = 4;
    scaleAnimation.fromValue = [NSNumber numberWithFloat:0.1];
    scaleAnimation.toValue = [NSNumber numberWithFloat:1];
    [animationView.layer addAnimation:scaleAnimation forKey:@"scale"];
    CABasicAnimation *breathOut = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    breathOut.duration = 8;
    breathOut.fromValue = [NSNumber numberWithFloat:1];
    breathOut.toValue = [NSNumber numberWithFloat:0.1];
    [animationView.layer removeAllAnimations];
   [animationView.layer addAnimation: breathOut forKey:@"scale"];
我还尝试使用scaleAnimation的委托

- (void)animationDidStop:(CABasicAnimation *)theAnimation2 finished:(BOOL)flag
这可以工作,但在动画完成后,圆将返回到第一个动画结束后的状态。收缩->动画结束->再次全尺寸


我不确定我在这里遗漏了什么。

CAAnimations不会将转换应用到您的层,它正在演示层上设置动画,然后在动画完成后切换回您的层

播放动画时应应用变换

-(void)breathOutAnimation
{
    CABasicAnimation *breathOut = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    breathOut.duration = 8;
    breathOut.fromValue = [NSNumber numberWithFloat:1];
    breathOut.toValue = [NSNumber numberWithFloat:0.1];
    [animationView.layer removeAllAnimations];
    [animationView.layer addAnimation: breathOut forKey:@"scale"];
    animationView.layer.transform = CATransform3DMakeScale(0.1, 0.1, 0.1);
}