iOS弹窗动画

2020-09-27  本文已影响0人  今年27
- (void)showInView:(UIView*)view{
    [view addSubview:self];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(view);
    }];
    
    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.duration      = 0.15;
    animation.repeatCount   = 1;
    animation.fromValue     = @0.0;
    animation.toValue       = @1.0;
    [self.innerView.layer addAnimation:animation forKey:@"scale-show-layer"];

}

关于这个RemovedOnCompletion和kCAFillModeForwards设置
如果设置了这两个属性,就不会在动画结束后恢复原样,而是保持弹窗动画后的样子

 CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.duration      = 0.15;
    animation.repeatCount   = 1;
    animation.fromValue     = @1.0;
    animation.toValue       = @0.0;
    
    //设置结束状态
    [animation setRemovedOnCompletion:NO];
    animation.fillMode = kCAFillModeForwards;
    [self.innerView.layer addAnimation:animation forKey:@"scale-show-layer"];

上一篇 下一篇

猜你喜欢

热点阅读