美文网首页
iOS-保存视图动画结束后的实际位置

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

作者: malgee | 来源:发表于2018-03-31 22:46 被阅读10次
      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];
        
    }
    

    相关文章

      网友评论

          本文标题:iOS-保存视图动画结束后的实际位置

          本文链接:https://www.haomeiwen.com/subject/dvincftx.html