iOS-保存视图动画结束后的实际位置

2018-03-31  本文已影响10人  malgee
  CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
        
        animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(loaderView.centerX, loaderView.centerY)];
        
        animation.toValue = [NSValue valueWithCGPoint:CGPointMake(loaderView.centerX, loaderView.centerY + 300)];
        
        animation.fillMode = kCAFillModeForwards;
        
        animation.removedOnCompletion = NO;
        
        animation.duration = 3;
        
        animation.delegate = self;
        
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        
        [loaderView.layer addAnimation:animation forKey:@"animation"];
        
        
        // 保存结束后的 实际位置
        NSValue *endValue = [NSValue valueWithCGPoint:CGPointMake(loaderView.centerX, loaderView.centerY + 300)];
        
        loaderView.layer.position= CGPointFromString([NSString stringWithFormat:@"%@", endValue]);


            [CATransaction begin];
            [CATransaction setAnimationDuration:3];
            [CATransaction setCompletionBlock:^{

                for (UIButton *btn in self.subViews) {
                    loaderView.transform = CGAffineTransformIdentity;

                }
                self.userInteractionEnabled = YES;
            }];
            
            [CATransaction commit];
- (void)addBounceAnimation
{
    NSString *keyPath = @"position.y";
    id finalValue = [NSNumber numberWithFloat:0.5 * (AWSCREENHEIGHT - (MGColorWidth + MGContentViewTopMargin)) + MGColorWidth * 0.5];
    
    SKBounceAnimation *bounceAnimation = [SKBounceAnimation animationWithKeyPath:keyPath];
    bounceAnimation.fromValue = [NSNumber numberWithFloat:self.center.x];
    bounceAnimation.toValue = finalValue;
    bounceAnimation.duration = 0.5f;
    bounceAnimation.numberOfBounces = 2;
    bounceAnimation.stiffness = SKBounceAnimationStiffnessLight;
    bounceAnimation.shouldOvershoot = YES;
    bounceAnimation.delegate = self;
    bounceAnimation.fillMode = kCAFillModeForwards;
    bounceAnimation.removedOnCompletion = NO;
    
    [bounceAnimation setValue:@"bounceAnimation" forKey:@"animationKey"];
    
    [self.layer addAnimation:bounceAnimation forKey:@"someKey"];

   // 这句修改实际的位置改变
    [self.layer setValue:finalValue forKeyPath:keyPath];
    
}
上一篇下一篇

猜你喜欢

热点阅读