美文网首页
iOS basic animation

iOS basic animation

作者: 松龄学编程 | 来源:发表于2020-08-05 08:42 被阅读0次
- (void)doShowupAnimation {
    CABasicAnimation* scaleAnima = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnima.fromValue = @0.8;
    scaleAnima.toValue = @1;
    scaleAnima.timingFunction = [CAMediaTimingFunction functionWithName:
    kCAMediaTimingFunctionEaseIn];
    
    CABasicAnimation *opacityAnima = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacityAnima.fromValue = @(0);
    opacityAnima.toValue = @(1);
    opacityAnima.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
    CAAnimationGroup *animaGroup = [CAAnimationGroup animation];
    animaGroup.duration = 0.15f;
    animaGroup.fillMode = kCAFillModeForwards;
    animaGroup.removedOnCompletion = NO;
    animaGroup.animations = @[scaleAnima,opacityAnima];
    [self.containerView.layer addAnimation:animaGroup forKey:@"showup"];
}

- (void)doDismissAnimation: (void(^)(Boolean)) completionHandler {
    CABasicAnimation* scaleAnima = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnima.fromValue = @1;
    scaleAnima.toValue = @0.8;
    scaleAnima.timingFunction = [CAMediaTimingFunction functionWithName:
    kCAMediaTimingFunctionEaseIn];
    
    CABasicAnimation *opacityAnima = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacityAnima.fromValue = @(1);
    opacityAnima.toValue = @(0);
    opacityAnima.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
    CAAnimationGroup *animaGroup = [CAAnimationGroup animation];
    animaGroup.duration = 0.15f;
    animaGroup.fillMode = kCAFillModeForwards;
    animaGroup.removedOnCompletion = NO;
    animaGroup.animations = @[scaleAnima,opacityAnima];
    animaGroup.delegate = self;
    [self.containerView.layer addAnimation:animaGroup forKey:@"dismiss"];
}

相关文章

网友评论

      本文标题:iOS basic animation

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